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