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