--- parser3/src/main/compile.y 2021/11/09 14:21:04 1.292 +++ parser3/src/main/compile.y 2024/09/28 14:37:53 1.298 @@ -2,13 +2,13 @@ /** @file Parser: compiler(lexical parser and grammar). - Copyright (c) 2001-2020 Art. Lebedev Studio (http://www.artlebedev.com) - Author: Alexander Petrosyan (http://design.ru/paf) + Copyright (c) 2001-2023 Art. Lebedev Studio (http://www.artlebedev.com) + Authors: Konstantin Morshnev , Alexandr Petrosian */ -volatile const char * IDENT_COMPILE_Y = "$Id: compile.y,v 1.292 2021/11/09 14:21:04 moko Exp $"; +volatile const char * IDENT_COMPILE_Y = "$Id: compile.y,v 1.298 2024/09/28 14:37:53 moko Exp $"; /** @todo parser4: @@ -62,7 +62,7 @@ static const VString vempty; #define POOL (*PC.pool) #ifndef DOXYGEN -#define CLASS_ADD if(PC.class_add()){ \ +#define CLASS_ADD if(!PC.class_add()){ \ PC.error=pa_strcat(PC.cclass->type(), " - class is already defined"); \ YYERROR; \ } @@ -172,7 +172,7 @@ control_method: '@' STRING '\n' PC.cclass_new=cclass; PC.append=false; } else { - YYERROR1("@" CLASS_NAME " must contain only one line with class name (contains more then one)"); + YYERROR1("@" CLASS_NAME " must contain only one line with class name (contains more than one)"); } } else if(command==USE_CONTROL_METHOD_NAME) { CLASS_ADD; @@ -440,14 +440,25 @@ construct: construct_square: '[' { // allow $result_or_other_variable[ letters here any time ] *reinterpret_cast(&$$)=PC.explicit_result; PC.explicit_result=false; -} any_constructor_code_value { + PC.array=false; // no need to save current value as if() is right after PC.array=true; +} any_constructor_code_values { PC.explicit_result=*reinterpret_cast(&$2); } ']' { // stack: context, name - $$=$3; // stack: context, name, value - O(*$$, OP::OP_CONSTRUCT_VALUE); /* value=pop; name=pop; context=pop; construct(context,name,value) */ + if(!PC.array){ + $$=$3; // stack: context, name, value + O(*$$, OP::OP_CONSTRUCT_VALUE); /* value=pop; name=pop; context=pop; construct(context,name,value) */ + } else { + $$ = N(); + OA(*$$, OP::OP_CONSTRUCT_ARRAY, $3); + PC.array=false; + } } ; +any_constructor_code_values: + any_constructor_code_value { $$ = $1; } + | any_constructor_code_values ';' any_constructor_code_value { $$ = $1; P(*$$, *$3); PC.array=true; }; +; construct_round: '(' expr_value ')' { $$=N(); // stack: context, name @@ -830,12 +841,12 @@ inline void ungetc(Parse_control& pc, ui } static int yylex(YYSTYPE *lvalp, void *apc) { - register Parse_control& pc=*static_cast(apc); + Parse_control& pc=*static_cast(apc); #define lexical_brackets_nestage pc.brackets_nestages[pc.ls_sp] #define RC {result=c; goto break2; } - register int c; + int c; int result; if(pc.pending_state) { @@ -1601,7 +1612,7 @@ break2: } static int real_yyerror(Parse_control *pc, const char *s) { // Called by yyparse on error - PC.error=s; + PC.error=pa_strdup(s); return 1; }