--- parser3/src/main/compile.y 2002/09/13 14:11:43 1.194 +++ parser3/src/main/compile.y 2003/04/07 07:07:30 1.205 @@ -2,10 +2,10 @@ /** @file Parser: compiler(lexical parser and grammar). - Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) + Copyright (c) 2001, 2003 ArtLebedev Group (http://www.artlebedev.com) Author: Alexander Petrosyan (http://design.ru/paf) - $Id: compile.y,v 1.194 2002/09/13 14:11:43 paf Exp $ + $Id: compile.y,v 1.205 2003/04/07 07:07:30 paf Exp $ */ /** @@ -34,8 +34,8 @@ #include "pa_vdouble.h" #include "pa_globals.h" #include "pa_vvoid.h" +#include "pa_vmethod_frame.h" -#define SELF_ELEMENT_NAME "self" #define USE_CONTROL_METHOD_NAME "USE" static int real_yyerror(parse_control *pc, char *s); @@ -44,6 +44,7 @@ static int yylex(YYSTYPE *lvalp, void *p // local convinient inplace typecast & var +#undef PC #define PC (*(parse_control *)pc) #define POOL (*PC.pool) #undef NEW @@ -72,6 +73,8 @@ static int yylex(YYSTYPE *lvalp, void *p %token NGE ">=" %token NEQ "==" %token NNE "!=" +%token NSL "<<" +%token NSR ">>" %token SLT "lt" %token SGT "gt" @@ -93,21 +96,24 @@ static int yylex(YYSTYPE *lvalp, void *p %left '<' '>' "<=" ">=" "lt" "gt" "le" "ge" %left "==" "!=" "eq" "ne" %left "is" "def" "in" "-f" "-d" -%left '!' /* bitwise */ %left "!|" %left '|' %left '&' -%left '~' +%left "<<" ">>" /* numerical */ -%left '-' '+' -%left '*' '/' '%' '\\' -%left NEG /* negation: unary - */ +%left '+' '-' +%left '*' '/' '\\' '%' +%left NUNARY /* unary - + */ + +/* out-of-group */ +%left '~' /* bitwise */ +%left '!' /* logical */ %% -all: +all: one_big_piece { Method& method=*NEW Method(POOL, PC.request->main_method_name, @@ -155,7 +161,7 @@ control_method: '@' STRING '\n' } } else if(command==USE_CONTROL_METHOD_NAME) { for(int i=0; isize(); i+=2) - PC.request->use_file(*LA2S(strings_code, i)); + PC.request->use_file(PC.request->main_class, *LA2S(strings_code, i)); } else if(command==BASE_NAME) { if(PC.cclass->base_class()) { // already changed from default? strcpy(PC.error, "class already have a base '"); @@ -525,8 +531,8 @@ expr: | '\'' string_inside_quotes_value '\'' { $$ = $2; } | '(' expr ')' { $$ = $2; } /* stack: operand // stack: @operand */ -| '-' expr %prec NEG { $$=$2; O($$, OP_NEG) } -| '+' expr %prec NEG { $$=$2 } +| '-' expr %prec NUNARY { $$=$2; O($$, OP_NEG) } +| '+' expr %prec NUNARY { $$=$2 } | '~' expr { $$=$2; O($$, OP_INV) } | '!' expr { $$=$2; O($$, OP_NOT) } | "def" expr { $$=$2; O($$, OP_DEF) } @@ -540,6 +546,8 @@ expr: | expr '/' expr { $$=$1; P($$, $3); O($$, OP_DIV) } | expr '%' expr { $$=$1; P($$, $3); O($$, OP_MOD) } | expr '\\' expr { $$=$1; P($$, $3); O($$, OP_INTDIV) } +| expr "<<" expr { $$=$1; P($$, $3); O($$, OP_BIN_SL) } +| expr ">>" expr { $$=$1; P($$, $3); O($$, OP_BIN_SR) } | 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) } @@ -637,7 +645,14 @@ static int yylex(YYSTYPE *lvalp, void *p } else // @ in first column inside some code [when could that be?] result=BAD_METHOD_DECL_START; goto break2; - } else if(c=='^') + } else if(c=='^') { + if(PC.ls==LS_METHOD_AFTER) { + // handle after-method situation + pop_LS(PC); + result=EON; + skip_analized=-1; // return to punctuation afterwards to assure it's literality + goto break2; + } switch(PC.ls) { case LS_EXPRESSION_VAR_NAME_WITH_COLON: case LS_EXPRESSION_VAR_NAME_WITHOUT_COLON: @@ -662,19 +677,12 @@ default: PC.string->APPEND_CLEAN(begin, end-begin, PC.file, begin_line); } // reset piece 'begin' position & line - end=begin=PC.source; // ^ + begin=PC.source; // ->punctuation begin_line=PC.line; - if(PC.ls==LS_METHOD_AFTER) { - pop_LS(PC); - result=EON; - skip_analized=-1; // return to ^ afterwards to assure it's literality - goto break2; - } else { - // skip over _ after ^ - PC.source++; PC.col++; - // skip analysis = forced literal - continue; - } + // skip over _ after ^ + PC.source++; PC.col++; + // skip analysis = forced literal + continue; // converting ^#HH into char(hex(HH)) case '#': @@ -698,13 +706,15 @@ default: PC.source+=3; PC.col+=3; // reset piece 'begin' position & line - begin=PC.source; // ^ + begin=PC.source; // ->after ^#HH begin_line=PC.line; + // skip analysis = forced literal continue; } break; } break; + } } // #comment start skipping if(c=='#' && PC.col==1) { @@ -910,17 +920,36 @@ default: 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; - } - } else - result=c; + + case '<': // <<, <=, < + switch(*PC.source) { + case '<': // <[<] + skip_analized=1; result=NSL; break; + case '=': // <[=] + skip_analized=1; result=NLE; break; + default: // <[] + result=c; break; + } + goto break2; + case '>': // >>, >=, > + switch(*PC.source) { + case '>': // >[>] + skip_analized=1; result=NSR; break; + case '=': // >[=] + skip_analized=1; result=NGE; break; + default: // >[] + result=c; break; + } + goto break2; + case '=': // == + switch(*PC.source) { + case '=': // =[=] + skip_analized=1; result=NEQ; break; + default: // =[] + result=c; break; // not used now + } goto break2; + case '"': push_LS(PC, LS_EXPRESSION_STRING_QUOTED); RC;