--- parser3/src/main/compile.y 2001/03/27 13:47:30 1.117 +++ parser3/src/main/compile.y 2001/04/06 10:20:36 1.124 @@ -5,7 +5,7 @@ Author: Alexander Petrosyan (http://design.ru/paf) - $Id: compile.y,v 1.117 2001/03/27 13:47:30 paf Exp $ + $Id: compile.y,v 1.124 2001/04/06 10:20:36 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" @@ -112,6 +113,7 @@ all: one_big_piece { Method& method=*NEW Method(POOL, *main_method_name, + Method::CT_ANY, 0, 0, /*min, max numbered_params_count*/ 0/*param_names*/, 0/*local_names*/, $1/*parser_code*/, 0/*native_code*/); @@ -126,7 +128,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, "@"); @@ -135,7 +137,7 @@ control_method: '@' STRING '\n' YYERROR; } if(command==CLASS_NAME) { - if(PC.cclass!=&PC.request->ROOT) { // already changed from default? + if(PC.cclass) { // already changed from default? strcpy(PC.error, "class already have a name '"); strncat(PC.error, PC.cclass->name().cstr(), 100); strcat(PC.error, "'"); @@ -143,12 +145,10 @@ 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); - // defaulting base. may change with @BASE - PC.cclass->set_base(PC.request->ROOT); // append to request's classes PC.request->classes().put(*name, PC.cclass); } else { @@ -159,16 +159,16 @@ 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? + if(PC.cclass->base()) { // already changed from default? strcpy(PC.error, "class already have a base '"); strncat(PC.error, PC.cclass->base()->name().cstr(), 100); strcat(PC.error, "'"); 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 +201,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(Value *value=LA2V(params_code)) // it is OP_VALUE + value? + if(!value->is_defined()) // value is VUnknown? + params_code=0; // ^zzz[] case. don't append lone empty param. + if(params_code) + P($$, params_code); // filling method_frame.store_params + O($$, OP_CALL); // method_frame=pop; ncontext=pop; call(ncontext,method_frame) stack: value }; call_name: name_without_curly_rdive; @@ -360,10 +368,6 @@ store_square_param: '[' store_code_param 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 +379,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 +391,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 +529,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) }; %% @@ -574,7 +577,7 @@ static int yylex(YYSTYPE *lvalp, void *p } else PC.col++; - if(c=='^') + if(c=='^' && PC.ls!=LS_COMMENT && PC.ls!=LS_DEF_COMMENT) switch(*PC.source) { // escaping: ^^ ^$ ^; ^) ^} ^( ^{ ^" case '^': case '$': case ';': @@ -583,7 +586,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 +600,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 +613,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 +628,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 +1054,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 +1078,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()); }