From 1755b9a1a4070502f4a46ba1f4accc6f9feb7fd4 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Sun, 23 Jun 2019 13:51:46 +1000 Subject: [PATCH] indent_test: reduce stack usage for preceding NEWLINEs In the cases where we allow preceding newlines (Statementlist Open Close) we current use one parse-stack from for each newline. While there are unlikely to be many, this is inelegant. Change the right-recursive form to use a left-recursive Newlines rule that absorbs one or more NEWLINEs using at most 2 stack frames. Signed-off-by: NeilBrown --- csrc/indent_test.mdc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/csrc/indent_test.mdc b/csrc/indent_test.mdc index 7e4f956..7b5fe5c 100644 --- a/csrc/indent_test.mdc +++ b/csrc/indent_test.mdc @@ -138,8 +138,10 @@ with complete bracketing and indenting. Program -> Statementlist ${ print_statement($1, 0); }$ $*statement + Newlines -> NEWLINE + | Newlines NEWLINE Statementlist -> Statements ${ $0 = $<1; }$ - | NEWLINE Statementlist ${ $0 = $<2; }$ + | Newlines Statements ${ $0 = $<2; }$ Statements -> Statements Statement ${ { @@ -155,9 +157,9 @@ $*statement | ERROR ${ printf("statement ERROR\n"); $0 = NULL; }$ Open -> { - | NEWLINE Open + | Newlines { Close -> } - | NEWLINE Close + | Newlines } Block -> Open Statementlist Close ${ $0 = $<2; }$ | Open SimpleStatements } ${ $0 = $<2; }$ | : SimpleStatements ${ $0 = $<2; }$ -- 2.43.0