--- parser3/src/main/compile.y 2002/09/13 11:35:13 1.192 +++ parser3/src/main/compile.y 2002/09/13 14:11:43 1.194 @@ -5,7 +5,7 @@ Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) Author: Alexander Petrosyan (http://design.ru/paf) - $Id: compile.y,v 1.192 2002/09/13 11:35:13 paf Exp $ + $Id: compile.y,v 1.194 2002/09/13 14:11:43 paf Exp $ */ /** @@ -60,10 +60,13 @@ static int yylex(YYSTYPE *lvalp, void *p %token BAD_STRING_COMPARISON_OPERATOR %token BAD_HEX_LITERAL %token BAD_METHOD_DECL_START +%token BAD_METHOD_PARAMETER_NAME_CHARACTER +%token BAD_MATH_OPERATOR_CHARACTER %token LAND "&&" %token LOR "||" -%token LXOR "##" +%token LXOR "!||" +%token NXOR "!|" %token NLE "<=" %token NGE ">=" @@ -84,7 +87,7 @@ static int yylex(YYSTYPE *lvalp, void *p %token IS "is" /* logical */ -%left "##" +%left "!||" %left "||" %left "&&" %left '<' '>' "<=" ">=" "lt" "gt" "le" "ge" @@ -93,7 +96,7 @@ static int yylex(YYSTYPE *lvalp, void *p %left '!' /* bitwise */ -%left '#' +%left "!|" %left '|' %left '&' %left '~' @@ -539,10 +542,10 @@ expr: | expr '\\' expr { $$=$1; P($$, $3); O($$, OP_INTDIV) } | expr '&' expr { $$=$1; P($$, $3); O($$, OP_BIN_AND) } | expr '|' expr { $$=$1; P($$, $3); O($$, OP_BIN_OR) } -| expr '#' expr { $$=$1; P($$, $3); O($$, OP_BIN_XOR) } +| expr "!|" expr { $$=$1; P($$, $3); O($$, OP_BIN_XOR) } | expr "&&" expr { $$=$1; OA($$, OP_NESTED_CODE, $3); O($$, OP_LOG_AND) } | expr "||" expr { $$=$1; OA($$, OP_NESTED_CODE, $3); O($$, OP_LOG_OR) } -| expr "##" expr { $$=$1; P($$, $3); O($$, OP_LOG_XOR) } +| expr "!||" expr { $$=$1; P($$, $3); O($$, OP_LOG_XOR) } | expr '<' expr { $$=$1; P($$, $3); O($$, OP_NUM_LT) } | expr '>' expr { $$=$1; P($$, $3); O($$, OP_NUM_GT) } | expr "<=" expr { $$=$1; P($$, $3); O($$, OP_NUM_LE) } @@ -642,7 +645,7 @@ case LS_VAR_NAME_SIMPLE_WITH_COLON: case LS_VAR_NAME_SIMPLE_WITHOUT_COLON: case LS_VAR_NAME_CURLY: case LS_METHOD_NAME: -case LS_COMMENT: +case LS_USER_COMMENT: case LS_DEF_COMMENT: // no literals in names, please break; @@ -710,7 +713,7 @@ default: PC.string->APPEND_CLEAN(begin, end-begin, PC.file, begin_line); } // fall into COMMENT lexical state [wait for \n] - push_LS(PC, LS_COMMENT); + push_LS(PC, LS_USER_COMMENT); continue; } switch(PC.ls) { @@ -749,7 +752,7 @@ default: break; // #COMMENT - case LS_COMMENT: + case LS_USER_COMMENT: if(c=='\n') { // skip comment begin=PC.source; @@ -797,7 +800,8 @@ default: case LS_DEF_PARAMS: switch(c) { case '$': // common error - RC; + result=BAD_METHOD_PARAMETER_NAME_CHARACTER; + goto break2; case ';': RC; case ']': @@ -846,6 +850,15 @@ default: else // PC.ls==LS_VAR_ROUND // variable constructor ended pop_LS(PC); // return to normal life RC; + case '#': // comment start skipping + if(end!=begin) { + // append piece till # + PC.string->APPEND_CLEAN(begin, end-begin, PC.file, begin_line); + } + // fall into COMMENT lexical state [wait for \n] + push_LS(PC, LS_EXPRESSION_COMMENT); + lexical_brackets_nestage=1; + continue; case '$': push_LS(PC, LS_EXPRESSION_VAR_NAME_WITH_COLON); RC; @@ -874,21 +887,36 @@ default: case '~': case ';': RC; - case '&': case '|': case '#': + case '&': case '|': if(*PC.source==c) { // && || - result=c=='#'?LXOR:c=='&'?LAND:LOR; + result=c=='&'?LAND:LOR; skip_analized=1; } else result=c; goto break2; - case '<': case '>': case '=': case '!': - if(*PC.source=='=') { // <= >= == != + case '!': + switch(PC.source[0]) { + case '|': // !| !|| + skip_analized=1; + if(PC.source[1]=='|') { + skip_analized++; + result=LXOR; + } else + result=NXOR; + goto break2; + case '=': // != + skip_analized=1; + result=NNE; + goto break2; + } + RC; + case '<': case '>': case '=': + if(*PC.source=='=') { // <= >= == skip_analized=1; switch(c) { case '<': result=NLE; break; case '>': result=NGE; break; case '=': result=NEQ; break; - case '!': result=NNE; break; } } else result=c; @@ -955,6 +983,24 @@ default: continue; } break; + case LS_EXPRESSION_COMMENT: + if(c=='(') + lexical_brackets_nestage++; + + switch(*PC.source) { + case '\n': case ')': + if(*PC.source==')') + if(--lexical_brackets_nestage!=0) + continue; + + // skip comment + begin=PC.source; + begin_line=PC.line; + + pop_LS(PC); + continue; + } + break; // VARIABLE GET/PUT/WITH case LS_VAR_NAME_SIMPLE_WITH_COLON: @@ -1218,7 +1264,7 @@ break2: if(end!=begin && end[-1]=='\n') // allow one empty line before LS_DEF_NAME end--; } - if(end!=begin && PC.ls!=LS_COMMENT) { // last piece still alive and not comment? + if(end!=begin && PC.ls!=LS_USER_COMMENT) { // last piece still alive and not comment? // append it PC.string->APPEND_CLEAN(begin, end-begin, PC.file, begin_line/*, start_col*/); }