From a571467ffc33a814c65f5a410a4f70509787b9aa Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Sun, 23 Jun 2019 14:29:13 +1000 Subject: [PATCH] oceani: modify grammar to not waste stack on newlines Current grammar uses one stack frame per newline for leading newlines as these productions are right-recursive. This is unnecessary and inelegant. Change to use a left-recursive Newlines production. Signed-off-by: NeilBrown --- csrc/oceani.mdc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/csrc/oceani.mdc b/csrc/oceani.mdc index d234968..06f71be 100644 --- a/csrc/oceani.mdc +++ b/csrc/oceani.mdc @@ -2022,17 +2022,19 @@ function will be needed. | DeclareStruct NEWLINE $void + Newlines -> NEWLINE + | Newlines NEWLINE Open -> { - | NEWLINE Open + | Newlines { Close -> } - | NEWLINE Close + | Newlines } $*fieldlist FieldBlock -> Open FieldList } ${ $0 = $<2; }$ | Open SimpleFieldList } ${ $0 = $<2; }$ | : FieldList $$NEWLINE ${ $0 = $<2; }$ FieldList -> FieldLines ${ $0 = $<1; }$ - | NEWLINE FieldLines ${ $0 = $<2; }$ + | Newlines FieldLines ${ $0 = $<2; }$ FieldLines -> SimpleFieldListLine ${ $0 = $<1; }$ | FieldLines SimpleFieldListLine ${ $2->prev = $<1; @@ -3061,7 +3063,7 @@ is in-place. | : Statementlist $$NEWLINE ${ $0 = $<2; }$ Statementlist -> ComplexStatements ${ $0 = reorder_bilist($<1); }$ - | NEWLINE Statementlist ${ $0 = $<2; }$ + | Newlines ComplexStatements ${ $0 = reorder_bilist($<2); }$ ComplexStatements -> ComplexStatements ComplexStatement ${ if ($2 == NULL) { @@ -3938,7 +3940,7 @@ various declarations in the parse context. $void Ocean -> DeclarationList - | NEWLINE Ocean + | Newlines DeclarationList DeclarationList -> Declaration | DeclarationList Declaration @@ -3985,7 +3987,7 @@ searching through for the Nth constant for decreasing N. | const SimpleConstList NEWLINE ConstList -> ConstLines - | NEWLINE ConstList + | Newlines ConstLines ConstLines -> ConstLines SimpleConstLine | SimpleConstLine SimpleConstList -> SimpleConstList ; Const -- 2.43.0