OptNL -> NEWLINE
|
-Newlines -> NEWLINE
- | NEWLINE Newlines
-
$*statement
- Statementlist -> SimpleStatements ${ $0 = $<1; }$
- | Statements ${ $0 = $<1; }$
+ Statementlist -> Statements ${ $0 = $<1; }$
Statements -> Statements Statement ${
{
*s = $<2;
}
}$
- | ${ $0 = NULL; }$
+ | Statement ${ $0 = $<1; }$
| ERROR ${ printf("statement ERROR\n"); $0 = NULL; }$
- Block -> OptNL { Statementlist OptNL } ${ $0 = $<3; }$
+ Open -> {
+ | NEWLINE {
+ Close -> }
+ | NEWLINE }
+ Block -> Open Statementlist Close ${ $0 = $<2; }$
+ | Open SimpleStatements } ${ $0 = $<2; }$
| : Statementlist ${ $0 = $2; $2 = NULL; }$
SimpleStatements -> SimpleStatements ; SimpleStatement ${
}
}$
| SimpleStatement ${ $0 = $<1; }$
+ | SimpleStatements ; ${ $0 = $<1; }$
SimpleStatement -> Factor = Expression ${
$0 = calloc(1, sizeof(struct statement));
$0->expr->op = $2.txt;
$0->expr->right = $<3;
}$
- Statement -> SimpleStatements Newlines ${
- $0 = $<1;
- }$
- | SimpleStatements ; Newlines ${
+ Statement -> SimpleStatements NEWLINE ${
$0 = $<1;
}$
| IfStatement ${ $0 = $<1; }$
+ | Statement NEWLINE ${ $0 = $<1; }$
- IfStatement -> if Expression Block ${
+ IfStatement -> if Expression Block OptNL ${
$0 = calloc(1, sizeof(struct statement));
$0->expr = $<2;
$0->thenpart = $<3;
}$
- | if Expression SimpleStatement ${
+ | if Expression : SimpleStatements ${
$0 = calloc(1, sizeof(struct statement));
$0->expr = $<2;
- $0->thenpart = $<3;
+ $0->thenpart = $<4;
}$
- | if Expression Block Newlines else Block ${
+ | if Expression Block OptNL else Block ${
$0 = calloc(1, sizeof(struct statement));
$0->expr = $<2;
$0->thenpart = $<3;
$0->elsepart = $<6;
}$
- | if Expression Block Newlines else IfStatement ${
+ | if Expression Block OptNL else : SimpleStatements ${
+ $0 = calloc(1, sizeof(struct statement));
+ $0->expr = $<2;
+ $0->thenpart = $<3;
+ $0->elsepart = $<7;
+ }$
+ | if Expression Block OptNL else IfStatement ${
$0 = calloc(1, sizeof(struct statement));
$0->expr = $<2;
$0->thenpart = $<3;