--- parser3/src/main/compile.y 2001/03/06 12:00:44 1.48 +++ parser3/src/main/compile.y 2001/03/06 13:24:40 1.52 @@ -1,5 +1,5 @@ /* - $Id: compile.y,v 1.48 2001/03/06 12:00:44 paf Exp $ + $Id: compile.y,v 1.52 2001/03/06 13:24:40 paf Exp $ */ %{ @@ -19,6 +19,7 @@ #include "pa_value.h" #include "pa_request.h" #include "pa_vobject.h" +#include "pa_vdouble.h" #define SELF_NAME "self" #define USES_NAME "USES" @@ -40,6 +41,7 @@ int yylex(YYSTYPE *lvalp, void *pc); %token EON %token STRING %token BOGUS +%token LOGICAL_AND LOGICAL_OR %% @@ -183,9 +185,9 @@ name_without_curly_rdive_code: name_adva /* put */ -put: '$' name_expr_wdive '[' constructor_value ']' { +put: '$' name_expr_wdive constructor_value { $$=$2; /* stack: context,name */ - P($$, $4); /* stack: context,name,constructor_value */ + P($$, $3); /* stack: context,name,constructor_value */ OP($$, OP_CONSTRUCT); /* value=pop; name=pop; context=pop; construct(context,name,value) */ }; name_expr_wdive: @@ -215,42 +217,37 @@ name_expr_wdive_root: ':' name_expr_dive name_expr_wdive_class: class_prefix name_expr_dive_code { $$=$1; P($$, $2) }; constructor_value: - constructor_one_param_value -| constructor_two_params_value /* $var(=;2*2) $var(%d;2*2) $var(+;1) */ + '[' constructor_code_value ']' { $$=$2 } +| '(' constructor_expression_value ')' { $$=$2 } ; - -constructor_one_param_value: - empty_value /* optimized $var() case */ -| STRING /* optimized $var(STRING) case */ -| complex_constructor_param_value /* $var(something complex) */ +constructor_code_value: + empty_value /* optimized $var[] case */ +| STRING /* optimized $var[STRING] case */ +| complex_constructor_code_value /* $var[something complex] */ ; -complex_constructor_param_value: complex_constructor_param_body { +complex_constructor_code_value: complex_constructor_code { $$=N(POOL); OP($$, OP_CREATE_EWPOOL); /* stack: empty write context */ P($$, $1); /* some codes to that context */ OP($$, OP_REDUCE_EWPOOL); /* context=pop; stack: context.value() */ }; -complex_constructor_param_body: codes__excluding_sole_str_literal; +complex_constructor_code: 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 { - char *operator_or_fmt=SLA2S($1)->cstr(); - $$=N(POOL); - P($$, $1); /* stack: ncontext name operator_or_fmt */ - P($$, $3); /* stack: ncontext name operator_or_fmt expr */ - switch(operator_or_fmt[0]) { - case '=': case '%': - OP($$, OP_EXPRESSION_EVAL); - break; - case '+': case '-': case '*': case '/': - OP($$, OP_MODIFY_EVAL); - break; - default: - strcpy(PC->error, "invalid modification operator"); - YYERROR; - } - /* stack: ncontext name value */ +constructor_expression_value: + empty_value /* optimized $var() case */ +| STRING /* optimized $var(STRING) case */ +;/*| complex_constructor_expression_value /* $var(something complex) * / +; +complex_constructor_expression_value: complex_constructor_expression { + $$=N(POOL); + OP($$, OP_CREATE_SWPOOL); /* stack: empty write context * / + P($$, $1); /* some codes to that context * / + OP($$, OP_REDUCE_SWPOOL); /* context=pop; stack: context.get_string() * / }; +complex_constructor_expression: +; +*/ /* call */ @@ -281,7 +278,7 @@ store_param_part: $$=$1; OP($$, OP_STORE_PARAM); } -| complex_constructor_param_value { /* (something complex) */ +| complex_constructor_code_value { /* (something complex) */ $$=$1; OP($$, OP_STORE_PARAM); } @@ -411,7 +408,7 @@ int yylex(YYSTYPE *lvalp, void *pc) { char *begin=PC->source; char *end; int begin_line=PC->line; - while(1) { + while(true) { c=*(end=(PC->source++)); if(c=='\n') { @@ -435,7 +432,7 @@ int yylex(YYSTYPE *lvalp, void *pc) { begin=PC->source; // ^ begin_line=PC->line; // skip over ^ and _ - PC->source++; + PC->source++; PC->col++; // skip analysis = forced literal continue; } @@ -493,7 +490,7 @@ int yylex(YYSTYPE *lvalp, void *pc) { case ']': PC->ls=*PC->source=='['?LS_DEF_LOCALS:LS_DEF_COMMENT; RC; - case c=='\n': // wrong. bailing out + case '\n': // wrong. bailing out pop_LS(PC); RC; } @@ -548,25 +545,32 @@ int yylex(YYSTYPE *lvalp, void *pc) { lexical_brackets_nestage++; RC; case '+': case '-': case '*': case '/': case '%': - case ';': - RC; case '&': case '|': case '<': case '>': case '=': case '!': - ? - break; + case ';': + RC; case '"': push_LS(PC, LS_EXPRESSION_STRING); RC; + case 'l': case 'g': case 'e': case 'n': + if(end==begin) // right after whitespace + switch(char next_c=*PC->source) { +// case '?': // ok [and bad cases, yacc would bark at them] + case 't': // lt gt [et nt] + case 'e': // le ge ne [ee] + case 'q': // eq [lq gq nq] + PC->source++; PC->col++; + PC->pending_state=next_c; + return c; + } break; case ' ': case '\t': case '\n': if(end!=begin) { // append piece till whitespace PC->string->APPEND(begin, end-begin, PC->file, begin_line); } - // skip over whitespace - PC->source++; // reset piece 'start' position & line - begin=PC->source; // ^ + begin=PC->source; // after whitespace begin_line=PC->line; continue; }