This uses the new $$NEWLINE are other techniques to ensure
blank lines are handled well.
We also test that adding blank lines everywhere doesn't break
anything.
Signed-off-by: NeilBrown <neil@brown.name>
checkitest: itest itest.code
@grep -v '^#' itest.out > .tmp.out
@./itest itest.code | diff -u - .tmp.out || echo itest FAILED
checkitest: itest itest.code
@grep -v '^#' itest.out > .tmp.out
@./itest itest.code | diff -u - .tmp.out || echo itest FAILED
+ @sed -e 'i\
+ ' itest.code > itest2.code
+ @./itest itest2.code| diff -u - .tmp.out || echo itest2 FAILED
demos :: doitest
tests :: checkitest
demos :: doitest
tests :: checkitest
Program -> Statementlist ${ print_statement($1, 0); }$
Program -> Statementlist ${ print_statement($1, 0); }$
$*statement
Statementlist -> Statements ${ $0 = $<1; }$
$*statement
Statementlist -> Statements ${ $0 = $<1; }$
+ | NEWLINE Statementlist ${ $0 = $<2; }$
Statements -> Statements Statement ${
{
Statements -> Statements Statement ${
{
| ERROR ${ printf("statement ERROR\n"); $0 = NULL; }$
Open -> {
| ERROR ${ printf("statement ERROR\n"); $0 = NULL; }$
Open -> {
Block -> Open Statementlist Close ${ $0 = $<2; }$
| Open SimpleStatements } ${ $0 = $<2; }$
Block -> Open Statementlist Close ${ $0 = $<2; }$
| Open SimpleStatements } ${ $0 = $<2; }$
- | : Statementlist ${ $0 = $<2; }$
+ | : SimpleStatements $$NEWLINE ${ $0 = $<2; }$
+ | : StatementBlock ${ $0 = $<2; }$
+ StatementBlock -> Statementlist $$NEWLINE ${ $0 = $<1; }$
SimpleStatements -> SimpleStatements ; SimpleStatement ${
{
SimpleStatements -> SimpleStatements ; SimpleStatement ${
{
$0->expr->op = $2.txt;
$0->expr->right = $<3;
}$
$0->expr->op = $2.txt;
$0->expr->right = $<3;
}$
- Statement -> SimpleStatements NEWLINE ${
- $0 = $<1;
- }$
+ SSline -> SimpleStatements NEWLINE ${ $0 = $<1; }$
+ | SSline NEWLINE ${ $0 = $<1; }$
+ Statement -> SSline ${ $0 = $<1; }$
| IfStatement ${ $0 = $<1; }$
| IfStatement ${ $0 = $<1; }$
- | Statement NEWLINE ${ $0 = $<1; }$
- IfStatement -> if Expression Block OptNL $$else ${
- $0 = calloc(1, sizeof(struct statement));
- $0->expr = $<2;
- $0->thenpart = $<3;
- }$
- | if Expression : SimpleStatements $$else ${
- $0 = calloc(1, sizeof(struct statement));
- $0->expr = $<2;
- $0->thenpart = $<4;
- }$
- | if Expression Block OptNL else Block ${
- $0 = calloc(1, sizeof(struct statement));
- $0->expr = $<2;
- $0->thenpart = $<3;
- $0->elsepart = $<6;
- }$
- | 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 ${
+ IfHead -> if Expression Block ${
$0 = calloc(1, sizeof(struct statement));
$0->expr = $<2;
$0->thenpart = $<3;
$0 = calloc(1, sizeof(struct statement));
$0->expr = $<2;
$0->thenpart = $<3;
+ | IfHead NEWLINE ${ $0 = $<1; }$
+ IfTail -> else Block ${ $0 = $<2; }$
+ | IfTail NEWLINE ${ $0 = $<1; }$
+
+ IfStatement -> IfHead $$else ${ $0 = $<1; }$
+ | IfHead IfTail ${
+ $0 = $<1;
+ $0->elsepart = $<2;
+ }$
+ | IfHead else IfStatement ${
+ $0 = $<1;
+ $0->elsepart = $<3;
+ }$
+ | IfStatement NEWLINE ${ $0 = $<1; }$
+
$*expression
Expression -> Expression + Term ${
$*expression
Expression -> Expression + Term ${