From 4caf4984763dd50d2bcc2f8127296df6587ea891 Mon Sep 17 00:00:00 2001 From: Danil-Zaripov Date: Fri, 6 Mar 2026 21:47:22 +0300 Subject: Improve list parsing The previous algorithm was O(n^2) --- src/inpla.y | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/inpla.y') diff --git a/src/inpla.y b/src/inpla.y index 0bdf4b4..bc612f7 100644 --- a/src/inpla.y +++ b/src/inpla.y @@ -195,7 +195,7 @@ static char *Errormsg = NULL; %token INTERFACE IFCE PRNAT FREE EXIT MEMSTAT %token END_OF_FILE USE -%type body astterm astterm_item nameterm agentterm astparam astparams +%type body astterm astterm_item nameterm agentterm astparam astparams_rev astparams val_declare rule ap aplist @@ -513,9 +513,13 @@ astparam | '(' astparams ')' { $$ = $2; } ; -astparams +astparams_rev : astterm { $$ = ast_makeList1($1); } -| astparams ',' astterm { $$ = ast_addLast($1, $3); } +| astparams_rev ',' astterm { $$ = ast_addFirst($1, $3); } +; + +astparams +: astparams_rev { $$ = ast_reverseList($1); } ; ap -- cgit v1.2.3