From f835bd19d1d65b1679f90aea56015704f11f8f4f Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sat, 18 Oct 2014 20:59:49 -0700 Subject: * parser.y: Allow TXR to support large programs, and efficiently so. (clauses_rev): New grammar symbol. Uses a left-recursive rule that does not consume an amount of parser stack proportional to the number of clauses, and sticks to efficient consing, which means that the list is built up in reverse. (clauses): Now just a wrapper rule for clauses_rev which nreverses its output. (clauses_opt): Retargetted to use clauses_rev instead of clauses, and reverse its output. --- parser.y | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'parser.y') diff --git a/parser.y b/parser.y index 2379602f..6dd79c30 100644 --- a/parser.y +++ b/parser.y @@ -97,7 +97,7 @@ int yylex(union YYSTYPE *, yyscan_t scanner); %token REGCHAR REGTOKEN LITCHAR SPLICE -%type spec clauses clauses_opt clause +%type spec clauses_rev clauses clauses_opt clause %type all_clause some_clause none_clause maybe_clause block_clause %type cases_clause choose_clause gather_clause collect_clause until_last %type collect_repeat @@ -144,11 +144,13 @@ spec : clauses { parser->syntax_tree = $1; } ; -clauses : clause { $$ = cons($1, nil); } - | clause clauses { $$ = cons($1, $2); } - ; +clauses : clauses_rev { $$ = nreverse($1); } + +clauses_rev : clause { $$ = cons($1, nil); } + | clauses_rev clause { $$ = cons($2, $1); } + ; -clauses_opt : clauses { $$ = $1; } +clauses_opt : clauses_rev { $$ = nreverse($1); } | /* empty */ { $$ = nil; } ; -- cgit v1.2.3