--- parser3/src/main/compile.y 2001/03/27 14:51:29 1.119 +++ parser3/src/main/compile.y 2001/03/29 15:00:21 1.121 @@ -5,7 +5,7 @@ Author: Alexander Petrosyan (http://design.ru/paf) - $Id: compile.y,v 1.119 2001/03/27 14:51:29 paf Exp $ + $Id: compile.y,v 1.121 2001/03/29 15:00:21 paf Exp $ */ /** @@ -39,6 +39,7 @@ #include "pa_vobject.h" #include "pa_vdouble.h" #include "pa_globals.h" +#include "pa_vunknown.h" #define SELF_ELEMENT_NAME "self" #define USE_CONTROL_METHOD_NAME "USE" @@ -126,7 +127,7 @@ method: control_method | code_method; control_method: '@' STRING '\n' control_strings { - const String& command=*SLA2S($2); + const String& command=*LA2S($2); YYSTYPE strings_code=$4; if(strings_code->size()<1*2) { strcpy(PC.error, "@"); @@ -143,7 +144,7 @@ control_method: '@' STRING '\n' } if(strings_code->size()==1*2) { // new class' name - const String *name=SLA2S(strings_code); + const String *name=LA2S(strings_code); // creating the class PC.cclass=NEW VClass(POOL); PC.cclass->set_name(*name); @@ -159,7 +160,7 @@ control_method: '@' STRING '\n' if(command==USE_CONTROL_METHOD_NAME) { for(int i=0; isize(); i+=2) PC.request->use_file( - PC.request->absolute(*SLA2S(strings_code, i))); + PC.request->absolute(*LA2S(strings_code, i))); } else if(command==BASE_NAME) { if(PC.cclass->base()!=&PC.request->ROOT) { // already changed from default? strcpy(PC.error, "class already have a base '"); @@ -168,7 +169,7 @@ control_method: '@' STRING '\n' YYERROR; } if(strings_code->size()==1*2) { - const String& base_name=*SLA2S(strings_code); + const String& base_name=*LA2S(strings_code); VClass *base=static_cast( PC.request->classes().get(base_name)); if(!base) { @@ -201,14 +202,14 @@ maybe_string: empty | STRING; code_method: '@' STRING bracketed_maybe_strings maybe_bracketed_strings maybe_comment '\n' maybe_codes { - const String *name=SLA2S($2); + const String *name=LA2S($2); YYSTYPE params_names_code=$3; Array *params_names=0; if(int size=params_names_code->size()) { params_names=NEW Array(POOL); for(int i=0; isize()) { locals_names=NEW Array(POOL); for(int i=0; isize()==3) // probably [] case. [OP_VALUE + Unknown + STORE_PARAM] + if(!LA2V(params_code)->is_defined()) { // value is VUnknown? + $$=N(POOL); // ^zzz[] case. don't append lone empty param. + break; + } + + $$=params_code; +}; store_round_param: '(' store_expr_param_parts ')' {$$=$2}; store_curly_param: '{' store_curly_param_parts '}' {$$=$2}; store_code_param_parts: - empty /* optimized [] case */ -| store_code_param_parts_not_empty -; -store_code_param_parts_not_empty: store_code_param_part | store_code_param_parts ';' store_code_param_part { $$=$1; P($$, $3) } ; @@ -375,16 +381,10 @@ store_curly_param_parts: store_curly_param_part | store_curly_param_parts ';' store_curly_param_part { $$=$1; P($$, $3) } ; -store_code_param_part: - STRING { /* optimized [STRING] case */ - $$=$1; - O($$, OP_STORE_PARAM); -} -| constructor_code_value { /* [something complex] */ +store_code_param_part: code_param_value { $$=$1; O($$, OP_STORE_PARAM); -} -; +}; store_expr_param_part: write_expr_value { $$=N(POOL); PEA($$, $1); @@ -393,6 +393,11 @@ store_curly_param_part: maybe_codes { $$=N(POOL); PCA($$, $1); }; +code_param_value: + unknown_value /* optimized [;...] case */ +| STRING /* optimized [STRING] case */ +| constructor_code_value /* [something complex] */ +; write_expr_value: expr_value { $$=$1; O($$, OP_WRITE_EXPR_RESULT); @@ -526,7 +531,7 @@ write_string: STRING { change_string_literal_to_write_string_literal($$=$1) }; -empty_string_value: /* empty */ { $$=VL(NEW VString(POOL)) }; +unknown_value: /* empty */ { $$=VL(NEW VUnknown(POOL)) }; empty: /* empty */ { $$=N(POOL) }; %% @@ -583,7 +588,7 @@ static int yylex(YYSTYPE *lvalp, void *p case '"': if(end!=begin) { // append piece till ^ - PC.string->APPEND(begin, end-begin, PC.file, begin_line); + PC.string->APPEND_CLEAN(begin, end-begin, PC.file, begin_line); } // reset piece 'begin' position & line begin=PC.source; // ^ @@ -597,7 +602,7 @@ static int yylex(YYSTYPE *lvalp, void *p case '#': if(end!=begin) { // append piece till ^ - PC.string->APPEND(begin, end-begin, PC.file, begin_line); + PC.string->APPEND_CLEAN(begin, end-begin, PC.file, begin_line); } // #HH ? if(PC.source[0]=='#' && PC.source[1] && PC.source[2]) { @@ -610,7 +615,7 @@ static int yylex(YYSTYPE *lvalp, void *p goto break2; // wrong hex value[no ^#00 chars allowed]: bail out } // append char(hex(HH)) - PC.string->APPEND(hex, 1, PC.file, begin_line); + PC.string->APPEND_CLEAN(hex, 1, PC.file, begin_line); // skip over ^#HH PC.source+=3; PC.col+=3; @@ -625,7 +630,7 @@ static int yylex(YYSTYPE *lvalp, void *p if(c=='#' && PC.col==1) { if(end!=begin) { // append piece till # - PC.string->APPEND(begin, end-begin, PC.file, begin_line); + PC.string->APPEND_CLEAN(begin, end-begin, PC.file, begin_line); } // fall into COMMENT lexical state [wait for \n] push_LS(PC, LS_COMMENT); @@ -1051,7 +1056,7 @@ break2: } if(end!=begin) { // last piece still alive? // append it - PC.string->APPEND(begin, end-begin, PC.file, begin_line/*, start_col*/); + PC.string->APPEND_CLEAN(begin, end-begin, PC.file, begin_line/*, start_col*/); } } if(PC.string->size()) { // something accumulated? @@ -1075,5 +1080,5 @@ static int real_yyerror(parse_control *p static void yyprint(FILE *file, int type, YYSTYPE value) { if(type==STRING) - fprintf(file, " \"%s\"", SLA2S(value)->cstr()); + fprintf(file, " \"%s\"", LA2S(value)->cstr()); }