From 1af6ccb6957677f4bbee2a628c0285df8564265e Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Thu, 2 Oct 2014 20:47:40 +1000 Subject: [PATCH] NEWLINE must only ever follow a 'linelike' symbol. Signed-off-by: NeilBrown --- csrc/indent_test.cgm | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/csrc/indent_test.cgm b/csrc/indent_test.cgm index ac3ab55..e7b176f 100644 --- a/csrc/indent_test.cgm +++ b/csrc/indent_test.cgm @@ -116,11 +116,11 @@ Program -> Statementlist ${ print_statement($1, 0); }$ OptNL -> NEWLINE | -OptSemi -> NEWLINE - | ; $*statement - Statementlist -> Statements ${ $0 = $<1; }$ + Statementlist -> SimpleStatements ${ $0 = $<1; }$ + | Statements ${ $0 = $<1; }$ + Statements -> Statements Statement ${ { struct statement **s; @@ -131,37 +131,57 @@ $*statement *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; -- 2.43.0