--- parser3/src/main/compile.y 2001/03/13 09:05:31 1.94 +++ parser3/src/main/compile.y 2001/03/16 09:52:59 1.103 @@ -3,7 +3,7 @@ Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) Author: Alexander Petrosyan (http://design.ru/paf) - $Id: compile.y,v 1.94 2001/03/13 09:05:31 paf Exp $ + $Id: compile.y,v 1.103 2001/03/16 09:52:59 paf Exp $ */ /* @@ -35,10 +35,10 @@ #include "pa_request.h" #include "pa_vobject.h" #include "pa_vdouble.h" -#include "core.h" +#include "pa_globals.h" #define SELF_ELEMENT_NAME "self" -#define USE_CONTROL_METHOD_NAME "use" +#define USE_CONTROL_METHOD_NAME "USE" int real_yyerror(parse_control *pc, char *s); static void yyprint(FILE *file, int type, YYSTYPE value); @@ -79,8 +79,10 @@ int yylex(YYSTYPE *lvalp, void *pc); %token DEF "def" %token IN "in" %token FEXISTS "-f" +%token IS "is" /* logical */ +%left "is" %left "lt" "gt" "le" "ge" %left "eq" "ne" %left '<' '>' "<=" ">=" "##" @@ -143,7 +145,6 @@ control_method: '@' STRING '\n' // defaulting base. may change with @BASE PC->cclass->set_base(PC->request->root_class); // append to request's classes - PC->request->classes_array()+=PC->cclass; PC->request->classes().put(*name, PC->cclass); } else { strcpy(PC->error, "@"CLASS_NAME" must contain sole name"); @@ -238,7 +239,7 @@ action: get | put | with | call; get: get_value { $$=$1; /* stack: resulting value */ - O($$, OP_WRITE); /* value=pop; wcontext.write(value) */ + O($$, OP_WRITE_VALUE); /* value=pop; wcontext.write(value) */ }; get_value: '$' get_name_value { $$=$2 } get_name_value: name_without_curly_rdive EON | name_in_curly_rdive; @@ -331,7 +332,7 @@ codes__excluding_sole_str_literal: actio call: call_value { $$=$1; /* stack: value */ - O($$, OP_WRITE); /* value=pop; wcontext.write(value) */ + O($$, OP_WRITE_VALUE); /* value=pop; wcontext.write(value) */ }; call_value: '^' call_name store_params EON { /* ^field.$method{vasya} */ $$=$2; /* with_xxx,diving code; stack: context,method_junction */ @@ -376,7 +377,7 @@ store_code_param_part: ; store_expr_param_part: write_expr_value { $$=N(POOL); - PCA($$, $1); + PEA($$, $1); }; store_curly_param_part: maybe_codes { $$=N(POOL); @@ -384,7 +385,7 @@ store_curly_param_part: maybe_codes { }; write_expr_value: expr_value { $$=$1; - O($$, OP_WRITE); + O($$, OP_WRITE_EXPR_RESULT); }; /* name */ @@ -418,7 +419,7 @@ name_expr_with_subvar_value: STRING subv $$=N(POOL); O($$, OP_CREATE_EWPOOL); P($$, $1); - O($$, OP_WRITE); + O($$, OP_WRITE_VALUE); P($$, $2); O($$, OP_REDUCE_EWPOOL); }; @@ -452,7 +453,7 @@ with: '$' name_without_curly_rdive '{' c O($$, OP_CREATE_RWPOOL); P($$, $4); O($$, OP_REDUCE_RWPOOL); - O($$, OP_WRITE); + O($$, OP_WRITE_VALUE); }; /* expr */ @@ -498,6 +499,7 @@ expr: | expr "ge" expr { $$=$1; P($$, $3); O($$, OP_STR_GE) } | expr "eq" expr { $$=$1; P($$, $3); O($$, OP_STR_EQ) } | expr "ne" expr { $$=$1; P($$, $3); O($$, OP_STR_NE) } +| expr "is" expr { $$=$1; P($$, $3); O($$, OP_IS) } ; string_inside_quotes_value: maybe_codes { @@ -510,7 +512,7 @@ string_inside_quotes_value: maybe_codes /* basics */ write_string: STRING { - // optimized from OP_STRING+OP_WRITE to OP_STRING__WRITE + // optimized from OP_STRING+OP_WRITE_VALUE to OP_STRING__WRITE change_string_literal_to_write_string_literal($$=$1) }; @@ -747,10 +749,19 @@ int yylex(YYSTYPE *lvalp, void *pc) { break; case 'i': if(end==begin) // right after whitespace - if(PC->source[0]=='n') { // in - skip_analized=1; - result=IN; - goto break2; + switch(PC->source[0]) { + case 'n': + { // in + skip_analized=1; + result=IN; + goto break2; + } + case 's': + { // is + skip_analized=1; + result=IS; + goto break2; + } } break; case 'd': @@ -797,6 +808,8 @@ int yylex(YYSTYPE *lvalp, void *pc) { case '+': case '*': case '/': case '%': case '&': case '|': case '=': case '!': + // common delimiters + case '\'': case ',': pop_LS(PC); PC->source--; if(--PC->col<0) { PC->line--; PC->col=-1; } result=EON; @@ -999,8 +1012,6 @@ break2: int real_yyerror(parse_control *pc, char *s) /* Called by yyparse on error */ { - //fprintf(stderr, "[%s]\n", s); - strncpy(pc->error, s, MAX_STRING); // TODO: перепроверить с треклятым последним байтом return 1; }