--- parser3/src/main/compile.y 2001/02/23 17:48:00 1.28 +++ parser3/src/main/compile.y 2001/02/24 09:00:11 1.31 @@ -1,5 +1,5 @@ /* - $Id: compile.y,v 1.28 2001/02/23 17:48:00 paf Exp $ + $Id: compile.y,v 1.31 2001/02/24 09:00:11 paf Exp $ */ %{ @@ -125,12 +125,6 @@ name_without_curly_rdive_code: name_adva /* put */ put: '$' name_expr_wdive '(' constructor_value ')' { -/* - TODO: подсмотреть в $3, и если там первым элементом self, - то выкинуть его и делать не WITH_WRITE, а WITH_SELF - если ничего не осталось - $self(xxx) - обругать -*/ $$=$2; /* stack: context,name */ P($$, $4); /* stack: context,name,constructor_value */ OP($$, OP_CONSTRUCT); /* value=pop; name=pop; context=pop; construct(context,name,value) */ @@ -158,14 +152,20 @@ name_expr_wdive_root: ':' name_expr_dive }; constructor_value: - constructor_one_param_value -| constructor_two_params_value /* $var(=;2*2) $var(%d;2*2) $var(+;1) */ + store_constructor_one_param_value +| store_constructor_two_params_value /* $var(=;2*2) $var(%d;2*2) $var(+;1) */ ; -constructor_one_param_value: - empty_value /* optimized $var() case */ -| STRING /* optimized $var(STRING) case */ -| complex_constructor_param_value /* $var(something complex) */ +store_constructor_one_param_value: + empty /* optimized $var() case */ +| STRING { /* optimized $var(STRING) case */ + $$=$1; + OP($$, OP_STORE_PARAM); +} +| complex_constructor_param_value { /* $var(something complex) */ + $$=$1; + OP($$, OP_STORE_PARAM); +} ; complex_constructor_param_value: complex_constructor_param_body { $$=N(POOL); @@ -176,7 +176,7 @@ complex_constructor_param_value: complex complex_constructor_param_body: codes__excluding_sole_str_literal; codes__excluding_sole_str_literal: action | code codes { $$=$1; P($$, $2) }; -constructor_two_params_value: STRING ';' constructor_one_param_value { +store_constructor_two_params_value: STRING ';' store_constructor_one_param_value { char *operator_or_fmt=LA2S($1)->cstr(); $$=N(POOL); P($$, $1); /* stack: ncontext name operator_or_fmt */ @@ -207,16 +207,13 @@ call: '^' name_without_curly_rdive store store_params: store_param | store_params store_param { $$=$1; P($$, $2) }; store_param: store_round_param | store_curly_param; store_round_param: '(' store_param_parts ')' {$$=$2}; -store_param_parts: store_param_part | store_param_parts ';' store_param_part { $$=$1; P($$, $3) }; -store_param_part: constructor_one_param_value { - $$=$1; - OP($$, OP_STORE_PARAM); -} +store_param_parts: + store_constructor_one_param_value +| store_param_parts ';' store_constructor_one_param_value { $$=$1; P($$, $3) } +; store_curly_param: '{' maybe_codes '}' { $$=N(POOL); - OP($$, OP_CODE_ARRAY); - AA($$, $2); - OP($$, OP_CREATE_JUNCTION); + PCA($$, $2); OP($$, OP_STORE_PARAM); }; @@ -286,12 +283,13 @@ with: '$' name_without_curly_rdive '{' c /* basics */ write_str_literal: STRING { - $$=$1; - OP($$, OP_WRITE); -}; -empty_value: empty { - $$=$1; - PVS($$, NEW VString(POOL)); + if(LA2S($1)->size()) { + $$=$1; + OP($$, OP_WRITE); + } else { + // optimized case of special end of macro. see yylex + $$=N(POOL); + } }; empty: /* empty */ { $$=N(POOL) }; @@ -623,8 +621,10 @@ break2: // strip last \n before LS_DEF_NAME or EOF if((c=='@' || c==0) && end[-1]=='\n') end--; - // append last piece - PC->string->APPEND(begin, end-begin, PC->file, begin_line/*, start_col*/); + if(end!=begin) { + // append last piece + PC->string->APPEND(begin, end-begin, PC->file, begin_line/*, start_col*/); + } // create STRING value: array of OP_VALUE+vstring *lvalp=L(NEW VString(PC->string)); // new pieces storage