|
|
| version 1.152, 2001/07/25 11:16:57 | version 1.181, 2002/02/18 12:05:02 |
|---|---|
| Line 1 | Line 1 |
| %{ | |
| /** @file | /** @file |
| Parser: compiler(lexical parser and grammar). | Parser: compiler(lexical parser and grammar). |
| Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) | Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) |
| Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf) | Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf) |
| $Id$ | |
| */ | */ |
| %{ | |
| static char *RCSId="$Id$"; | |
| /** | /** |
| @todo parser4: | @todo parser4: |
| Line 59 static int yylex(YYSTYPE *lvalp, void *p | Line 59 static int yylex(YYSTYPE *lvalp, void *p |
| %token BAD_STRING_COMPARISON_OPERATOR | %token BAD_STRING_COMPARISON_OPERATOR |
| %token BAD_HEX_LITERAL | %token BAD_HEX_LITERAL |
| %token BAD_METHOD_DECL_START | |
| %token LAND "&&" | %token LAND "&&" |
| %token LOR "||" | %token LOR "||" |
| Line 99 static int yylex(YYSTYPE *lvalp, void *p | Line 100 static int yylex(YYSTYPE *lvalp, void *p |
| /* numerical */ | /* numerical */ |
| %left '-' '+' | %left '-' '+' |
| %left '*' '/' '%' | %left '*' '/' '%' '\\' |
| %left NEG /* negation: unary - */ | %left NEG /* negation: unary - */ |
| %% | %% |
| Line 151 control_method: '@' STRING '\n' | Line 152 control_method: '@' STRING '\n' |
| } | } |
| } else if(command==USE_CONTROL_METHOD_NAME) { | } else if(command==USE_CONTROL_METHOD_NAME) { |
| for(int i=0; i<strings_code->size(); i+=2) | for(int i=0; i<strings_code->size(); i+=2) |
| PC.request->use_file( | PC.request->use_file(*LA2S(strings_code, i)); |
| PC.request->absolute(*LA2S(strings_code, i))); | |
| } else if(command==BASE_NAME) { | } else if(command==BASE_NAME) { |
| if(PC.cclass->base()) { // already changed from default? | if(PC.cclass->base()) { // already changed from default? |
| strcpy(PC.error, "class already have a base '"); | strcpy(PC.error, "class already have a base '"); |
| Line 242 get: get_value { | Line 242 get: get_value { |
| $$=$1; /* stack: resulting value */ | $$=$1; /* stack: resulting value */ |
| O($$, OP_WRITE_VALUE); /* value=pop; wcontext.write(value) */ | O($$, OP_WRITE_VALUE); /* value=pop; wcontext.write(value) */ |
| }; | }; |
| get_value: '$' get_name_value { $$=$2 } | get_value: '$' get_name_value { $$=$2 }; |
| get_name_value: name_without_curly_rdive EON | name_in_curly_rdive; | get_name_value: name_without_curly_rdive EON | name_in_curly_rdive; |
| name_in_curly_rdive: '{' name_without_curly_rdive '}' { $$=$2 }; | name_in_curly_rdive: '{' name_without_curly_rdive '}' { $$=$2 }; |
| name_without_curly_rdive: | name_without_curly_rdive: |
| name_without_curly_rdive_read | name_without_curly_rdive_read |
| | name_without_curly_rdive_root | |
| | name_without_curly_rdive_class; | | name_without_curly_rdive_class; |
| name_without_curly_rdive_read: name_without_curly_rdive_code { | name_without_curly_rdive_read: name_without_curly_rdive_code { |
| $$=N(POOL); | $$=N(POOL); |
| Array *diving_code=$1; | Array *diving_code=$1; |
| const String *first_name=LA2S(diving_code); | const String *first_name=LA2S(diving_code); |
| // self.xxx... -> xxx... | |
| // OP_VALUE+string+OP_GET_ELEMENT+... -> OP_WITH_SELF+... | |
| if(first_name && *first_name==SELF_ELEMENT_NAME) { | if(first_name && *first_name==SELF_ELEMENT_NAME) { |
| O($$, OP_WITH_SELF); /* stack: starting context */ | O($$, OP_WITH_SELF); /* stack: starting context */ |
| P($$, diving_code, | P($$, diving_code, |
| /* skip over... */ | /* skip over... */ |
| diving_code->size()>2?3/*OP_+string+get_element*/:2/*OP_+string*/); | diving_code->size()>=3?3/*OP_VALUE+string+OP_GET_ELEMENTx*/:2/*OP_+string*/); |
| } else { | } else { |
| O($$, OP_WITH_READ); /* stack: starting context */ | O($$, OP_WITH_READ); /* stack: starting context */ |
| // ^if ELEMENT -> ^if ELEMENT_OR_OPERATOR | |
| // OP_VALUE+string+OP_GET_ELEMENT. -> OP_VALUE+string+OP_GET_ELEMENT_OR_OPERATOR. | |
| if(PC.in_call_value && diving_code->size()==3) | |
| diving_code->put_int(2, OP_GET_ELEMENT_OR_OPERATOR); | |
| P($$, diving_code); | P($$, diving_code); |
| } | } |
| /* diving code; stack: current context */ | /* diving code; stack: current context */ |
| }; | }; |
| name_without_curly_rdive_root: ':' name_without_curly_rdive_code { | |
| $$=N(POOL); | |
| O($$, OP_WITH_ROOT); /* stack: starting context */ | |
| P($$, $2); /* diving code; stack: current context */ | |
| }; | |
| name_without_curly_rdive_class: class_prefix name_without_curly_rdive_code { $$=$1; P($$, $2) }; | name_without_curly_rdive_class: class_prefix name_without_curly_rdive_code { $$=$1; P($$, $2) }; |
| name_without_curly_rdive_code: name_advance2 | name_path name_advance2 { $$=$1; P($$, $2) }; | name_without_curly_rdive_code: name_advance2 | name_path name_advance2 { $$=$1; P($$, $2) }; |
| Line 279 put: '$' name_expr_wdive construct { | Line 280 put: '$' name_expr_wdive construct { |
| P($$, $3); /* stack: context,name,constructor_value */ | P($$, $3); /* stack: context,name,constructor_value */ |
| }; | }; |
| name_expr_wdive: | name_expr_wdive: |
| name_expr_wdive_write | name_expr_wdive_root |
| | name_expr_wdive_root | | name_expr_wdive_write |
| | name_expr_wdive_class; | | name_expr_wdive_class; |
| name_expr_wdive_write: name_expr_dive_code { | name_expr_wdive_root: name_expr_dive_code { |
| $$=N(POOL); | $$=N(POOL); |
| Array *diving_code=$1; | Array *diving_code=$1; |
| const String *first_name=LA2S(diving_code); | const String *first_name=LA2S(diving_code); |
| // $self.xxx... -> $xxx... | |
| // OP_VALUE+string+OP_GET_ELEMENT+... -> OP_WITH_SELF+... | |
| if(first_name && *first_name==SELF_ELEMENT_NAME) { | if(first_name && *first_name==SELF_ELEMENT_NAME) { |
| O($$, OP_WITH_SELF); /* stack: starting context */ | O($$, OP_WITH_SELF); /* stack: starting context */ |
| P($$, diving_code, | P($$, diving_code, |
| /* skip over... */ | /* skip over... */ |
| diving_code->size()>2?3/*OP_+string+get_element*/:2/*OP_+string*/); | diving_code->size()>=3?3/*OP_VALUE+string+OP_GET_ELEMENTx*/:2/*OP_+string*/); |
| } else { | } else { |
| O($$, OP_WITH_WRITE); /* stack: starting context */ | O($$, OP_WITH_ROOT); /* stack: starting context */ |
| P($$, diving_code); | P($$, diving_code); |
| } | } |
| /* diving code; stack: current context */ | /* diving code; stack: current context */ |
| }; | }; |
| name_expr_wdive_root: ':' name_expr_dive_code { | name_expr_wdive_write: '.' name_expr_dive_code { |
| $$=N(POOL); | $$=N(POOL); |
| O($$, OP_WITH_ROOT); /* stack: starting context */ | O($$, OP_WITH_WRITE); /* stack: starting context */ |
| P($$, $2); /* diving code; stack: context,name */ | P($$, $2); /* diving code; stack: context,name */ |
| }; | }; |
| name_expr_wdive_class: class_prefix name_expr_dive_code { $$=$1; P($$, $2) }; | name_expr_wdive_class: class_prefix name_expr_dive_code { $$=$1; P($$, $2) }; |
| construct: | construct: |
| construct_square | | construct_square |
| construct_round | | | construct_round |
| construct_curly | | construct_curly |
| ; | ; |
| construct_square: '[' any_constructor_code_value ']' { | construct_square: '[' any_constructor_code_value ']' { |
| // stack: context, name | // stack: context, name |
| Line 318 construct_square: '[' any_constructor_co | Line 321 construct_square: '[' any_constructor_co |
| construct_round: '(' expr_value ')' { | construct_round: '(' expr_value ')' { |
| // stack: context, name | // stack: context, name |
| $$=$2; // stack: context, name, value | $$=$2; // stack: context, name, value |
| O($$, OP_CONSTRUCT_EXPR); /* value=pop; name=pop; context=pop; construct(context,name,value) */ | O($$, OP_CONSTRUCT_EXPR); /* value=pop->as_expr_result; name=pop; context=pop; construct(context,name,value) */ |
| } | } |
| ; | ; |
| construct_curly: '{' maybe_codes '}' { | construct_curly: '{' maybe_codes '}' { |
| Line 328 construct_curly: '{' maybe_codes '}' { | Line 331 construct_curly: '{' maybe_codes '}' { |
| }; | }; |
| any_constructor_code_value: | any_constructor_code_value: |
| empty_string_value /* optimized $var[] case */ | void_value /* optimized $var[] case */ |
| | STRING /* optimized $var[STRING] case */ | | STRING /* optimized $var[STRING] case */ |
| | constructor_code_value /* $var[something complex] */ | | constructor_code_value /* $var[something complex] */ |
| ; | ; |
| Line 347 call: call_value { | Line 350 call: call_value { |
| $$=$1; /* stack: value */ | $$=$1; /* stack: value */ |
| O($$, OP_WRITE_VALUE); /* value=pop; wcontext.write(value) */ | O($$, OP_WRITE_VALUE); /* value=pop; wcontext.write(value) */ |
| }; | }; |
| call_value: '^' call_name store_params EON { /* ^field.$method{vasya} */ | call_value: '^' { |
| $$=$2; /* with_xxx,diving code; stack: context,method_junction */ | PC.in_call_value=true; |
| } | |
| call_name { | |
| PC.in_call_value=false; | |
| } | |
| store_params EON { /* ^field.$method{vasya} */ | |
| $$=$3; /* with_xxx,diving code; stack: context,method_junction */ | |
| O($$, OP_GET_METHOD_FRAME); /* stack: context,method_frame */ | O($$, OP_GET_METHOD_FRAME); /* stack: context,method_frame */ |
| YYSTYPE params_code=$3; | YYSTYPE params_code=$5; |
| if(params_code->size()==3) // probably [] case. [OP_VALUE + Void + STORE_PARAM] | if(params_code->size()==3) // probably [] case. [OP_VALUE + Void + STORE_PARAM] |
| if(Value *value=LA2V(params_code)) // it is OP_VALUE + value? | if(Value *value=LA2V(params_code)) // it is OP_VALUE + value? |
| if(!value->is_defined()) // value is VVoid? | if(!value->is_defined()) // value is VVoid? |
| Line 397 store_curly_param_part: maybe_codes { | Line 406 store_curly_param_part: maybe_codes { |
| PCA($$, $1); | PCA($$, $1); |
| }; | }; |
| code_param_value: | code_param_value: |
| empty_void_value /* optimized [;...] case */ | void_value /* optimized [;...] case */ |
| | STRING /* optimized [STRING] case */ | | STRING /* optimized [STRING] case */ |
| | constructor_code_value /* [something complex] */ | | constructor_code_value /* [something complex] */ |
| ; | ; |
| Line 413 name_expr_dive_code: name_expr_value | n | Line 422 name_expr_dive_code: name_expr_value | n |
| name_path: name_step | name_path name_step { $$=$1; P($$, $2) }; | name_path: name_step | name_path name_step { $$=$1; P($$, $2) }; |
| name_step: name_advance1 '.'; | name_step: name_advance1 '.'; |
| name_advance1: name_expr_value { | name_advance1: name_expr_value { |
| // we know that name_advance1 not called from ^xxx context | |
| // so we'll not check for operator call possibility as we do in name_advance2 | |
| /* stack: context */ | /* stack: context */ |
| $$=$1; /* stack: context,name */ | $$=$1; /* stack: context,name */ |
| O($$, OP_GET_ELEMENT); /* name=pop; context=pop; stack: context.get_element(name) */ | O($$, OP_GET_ELEMENT); /* name=pop; context=pop; stack: context.get_element(name) */ |
| Line 427 name_advance2: name_expr_value { | Line 439 name_advance2: name_expr_value { |
| name_expr_value: | name_expr_value: |
| STRING /* subname_is_const */ | STRING /* subname_is_const */ |
| | name_expr_subvar_value /* $subname_is_var_value */ | | name_expr_subvar_value /* $subname_is_var_value */ |
| | name_expr_with_subvar_value /* xxx$part_of_subname_is_var_value[$...] */ | | name_expr_with_subvar_value /* xxx$part_of_subname_is_var_value */ |
| | name_square_code_value /* [codes] */ | |
| ; | ; |
| name_expr_subvar_value: '$' subvar_ref_name_rdive { | name_expr_subvar_value: '$' subvar_ref_name_rdive { |
| $$=$2; | $$=$2; |
| Line 441 name_expr_with_subvar_value: STRING subv | Line 454 name_expr_with_subvar_value: STRING subv |
| P($$, $2); | P($$, $2); |
| O($$, OP_REDUCE_EWPOOL); | O($$, OP_REDUCE_EWPOOL); |
| }; | }; |
| subvar_ref_name_rdive: subvar_ref_name_rdive_read | subvar_ref_name_rdive_root; | name_square_code_value: '[' codes ']' { |
| subvar_ref_name_rdive_read: STRING { | |
| $$=N(POOL); | $$=N(POOL); |
| O($$, OP_WITH_READ); | O($$, OP_CREATE_EWPOOL); |
| P($$, $1); | P($$, $2); |
| O($$, OP_REDUCE_EWPOOL); | |
| }; | }; |
| subvar_ref_name_rdive_root: ':' STRING { | subvar_ref_name_rdive: STRING { |
| $$=N(POOL); | $$=N(POOL); |
| O($$, OP_WITH_ROOT); | O($$, OP_WITH_READ); |
| P($$, $2); | P($$, $1); |
| }; | }; |
| subvar_get_writes: subvar__get_write | subvar_get_writes subvar__get_write { $$=$1; P($$, $2) }; | subvar_get_writes: subvar__get_write | subvar_get_writes subvar__get_write { $$=$1; P($$, $2) }; |
| subvar__get_write: '$' subvar_ref_name_rdive { | subvar__get_write: '$' subvar_ref_name_rdive { |
| Line 458 subvar__get_write: '$' subvar_ref_name_r | Line 471 subvar__get_write: '$' subvar_ref_name_r |
| O($$, OP_GET_ELEMENT__WRITE); | O($$, OP_GET_ELEMENT__WRITE); |
| }; | }; |
| class_prefix: STRING ':' { | class_prefix: |
| class_static_prefix | |
| | class_constructor_prefix | |
| ; | |
| class_static_prefix: STRING ':' { | |
| $$=$1; // stack: class name string | $$=$1; // stack: class name string |
| O($$, OP_GET_CLASS); | O($$, OP_GET_CLASS); |
| }; | }; |
| class_constructor_prefix: class_static_prefix ':' { | |
| $$=$1; | |
| if(!PC.in_call_value) { | |
| strcpy(PC.error, ":: not allowed here"); | |
| YYERROR; | |
| } | |
| O($$, OP_PREPARE_TO_CONSTRUCT_OBJECT); | |
| }; | |
| /* expr */ | /* expr */ |
| Line 479 expr: | Line 504 expr: |
| | '(' expr ')' { $$ = $2; } | | '(' expr ')' { $$ = $2; } |
| /* stack: operand // stack: @operand */ | /* stack: operand // stack: @operand */ |
| | '-' expr %prec NEG { $$=$2; O($$, OP_NEG) } | | '-' expr %prec NEG { $$=$2; O($$, OP_NEG) } |
| | '+' expr %prec NEG { $$=$2 } | |
| | '~' expr { $$=$2; O($$, OP_INV) } | | '~' expr { $$=$2; O($$, OP_INV) } |
| | '!' expr { $$=$2; O($$, OP_NOT) } | | '!' expr { $$=$2; O($$, OP_NOT) } |
| | "def" expr { $$=$2; O($$, OP_DEF) } | | "def" expr { $$=$2; O($$, OP_DEF) } |
| Line 491 expr: | Line 517 expr: |
| | expr '*' expr { $$=$1; P($$, $3); O($$, OP_MUL) } | | expr '*' expr { $$=$1; P($$, $3); O($$, OP_MUL) } |
| | expr '/' expr { $$=$1; P($$, $3); O($$, OP_DIV) } | | expr '/' expr { $$=$1; P($$, $3); O($$, OP_DIV) } |
| | expr '%' expr { $$=$1; P($$, $3); O($$, OP_MOD) } | | expr '%' expr { $$=$1; P($$, $3); O($$, OP_MOD) } |
| | 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_AND) } |
| | expr '|' expr { $$=$1; P($$, $3); O($$, OP_BIN_OR) } | | 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; P($$, $3); O($$, OP_LOG_AND) } | | expr "&&" expr { $$=$1; PNC($$, $3); O($$, OP_LOG_AND) } |
| | expr "||" expr { $$=$1; P($$, $3); O($$, OP_LOG_OR) } | | expr "||" expr { $$=$1; PNC($$, $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_LT) } |
| | expr '>' expr { $$=$1; P($$, $3); O($$, OP_NUM_GT) } | | expr '>' expr { $$=$1; P($$, $3); O($$, OP_NUM_GT) } |
| Line 526 write_string: STRING { | Line 553 write_string: STRING { |
| change_string_literal_to_write_string_literal($$=$1) | change_string_literal_to_write_string_literal($$=$1) |
| }; | }; |
| empty_void_value: /* empty */ { $$=VL(NEW VVoid(POOL)) }; | void_value: /* empty */ { $$=VL(NEW VVoid(POOL)) }; |
| empty_string_value: /* empty */ { $$=VL(NEW VString(POOL)) }; | |
| empty: /* empty */ { $$=N(POOL) }; | empty: /* empty */ { $$=N(POOL) }; |
| %% | %% |
| Line 550 empty: /* empty */ { $$=N(POOL) }; | Line 576 empty: /* empty */ { $$=N(POOL) }; |
| */ | */ |
| static int yylex(YYSTYPE *lvalp, void *pc) { | static int yylex(YYSTYPE *lvalp, void *pc) { |
| #define lexical_brackets_nestage PC.brackets_nestages[PC.sp] | #define lexical_brackets_nestage PC.brackets_nestages[PC.ls_sp] |
| #define RC {result=c; goto break2; } | #define RC {result=c; goto break2; } |
| register int c; | register int c; |
| Line 568 static int yylex(YYSTYPE *lvalp, void *p | Line 594 static int yylex(YYSTYPE *lvalp, void *p |
| int skip_analized=0; | int skip_analized=0; |
| while(true) { | while(true) { |
| c=*(end=(PC.source++)); | c=*(end=(PC.source++)); |
| // fprintf(stderr, "\nchar: %c %02X; nestage: %d, sp=%d", c, c, lexical_brackets_nestage, PC.sp); | |
| if(c=='\n') { | if(c=='\n') { |
| PC.line++; | PC.line++; |
| Line 575 static int yylex(YYSTYPE *lvalp, void *p | Line 602 static int yylex(YYSTYPE *lvalp, void *p |
| } else | } else |
| PC.col++; | PC.col++; |
| if(c=='^' && PC.ls!=LS_COMMENT && PC.ls!=LS_DEF_COMMENT) | if(c=='@' && PC.col==0+1) { |
| if(PC.ls==LS_DEF_SPECIAL_BODY) { | |
| // @SPECIAL | |
| // ... | |
| // @<here = | |
| pop_LS(PC); // exiting from LS_DEF_SPECIAL_BODY state | |
| } // continuing checks | |
| if(PC.ls==LS_USER) { | |
| push_LS(PC, LS_DEF_NAME); | |
| RC; | |
| } else // @ in first column inside some code [when could that be?] | |
| result=BAD_METHOD_DECL_START; | |
| goto break2; | |
| } else if(c=='^') | |
| switch(PC.ls) { | |
| case LS_EXPRESSION_VAR_NAME_WITH_COLON: | |
| case LS_EXPRESSION_VAR_NAME_WITHOUT_COLON: | |
| 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_DEF_COMMENT: | |
| // no literals in names, please | |
| break; | |
| default: | |
| switch(*PC.source) { | switch(*PC.source) { |
| // escaping: ^^ & co | // ^escaping some punctuators |
| case '^': case '$': case ';': | case '^': case '$': case ';': |
| case '(': case ')': | case '(': case ')': |
| case '[': case ']': | case '[': case ']': |
| case '{': case '}': | case '{': case '}': |
| case '"': | case '"': case ':': |
| if(end!=begin) { | if(end!=begin) { |
| // append piece till ^ | // append piece till ^ |
| PC.string->APPEND_CLEAN(begin, end-begin, PC.file, begin_line); | PC.string->APPEND_CLEAN(begin, end-begin, PC.file, begin_line); |
| } | } |
| // reset piece 'begin' position & line | // reset piece 'begin' position & line |
| begin=PC.source; // ^ | end=begin=PC.source; // ^ |
| begin_line=PC.line; | begin_line=PC.line; |
| // skip over ^ and _ | if(PC.ls==LS_METHOD_AFTER) { |
| PC.source++; PC.col++; | pop_LS(PC); |
| // skip analysis = forced literal | result=EON; |
| continue; | 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; | |
| } | |
| // converting ^#HH into char(hex(HH)) | // converting ^#HH into char(hex(HH)) |
| case '#': | case '#': |
| Line 623 static int yylex(YYSTYPE *lvalp, void *p | Line 682 static int yylex(YYSTYPE *lvalp, void *p |
| } | } |
| break; | break; |
| } | } |
| break; | |
| } | |
| // #comment start skipping | // #comment start skipping |
| if(c=='#' && PC.col==1) { | if(c=='#' && PC.col==1) { |
| if(end!=begin) { | if(end!=begin) { |
| Line 631 static int yylex(YYSTYPE *lvalp, void *p | Line 692 static int yylex(YYSTYPE *lvalp, void *p |
| } | } |
| // fall into COMMENT lexical state [wait for \n] | // fall into COMMENT lexical state [wait for \n] |
| push_LS(PC, LS_COMMENT); | push_LS(PC, LS_COMMENT); |
| continue; | |
| } | } |
| switch(PC.ls) { | switch(PC.ls) { |
| // USER'S = NOT OURS | // USER'S = NOT OURS |
| case LS_USER: | case LS_USER: |
| if(PC.skipping_bof_empty_lines) | case LS_NAME_SQUARE_PART: // name.[here].xxx |
| if(c=='\n') { | if(PC.trim_bof) |
| switch(c) { | |
| case '\n': case ' ': case '\t': | |
| begin=PC.source; | begin=PC.source; |
| begin_line=PC.line; | begin_line=PC.line; |
| continue; // skip it | continue; // skip it |
| default: | |
| PC.trim_bof=false; | |
| } | } |
| PC.skipping_bof_empty_lines=false; | |
| switch(c) { | switch(c) { |
| case '$': | case '$': |
| push_LS(PC, LS_VAR_NAME_SIMPLE); | push_LS(PC, LS_VAR_NAME_SIMPLE_WITH_COLON); |
| RC; | RC; |
| case '^': | case '^': |
| push_LS(PC, LS_METHOD_NAME); | push_LS(PC, LS_METHOD_NAME); |
| RC; | RC; |
| case '@': | case ']': |
| if(PC.col==0+1) { | if(PC.ls==LS_NAME_SQUARE_PART) |
| push_LS(PC, LS_DEF_NAME); | if(--lexical_brackets_nestage==0) {// $name.[co<]?>de<]?> |
| RC; | pop_LS(PC); // $name.[co<]>de<]!> |
| } | RC; |
| } | |
| break; | |
| case '[': // $name.[co<[>de] | |
| if(PC.ls==LS_NAME_SQUARE_PART) | |
| lexical_brackets_nestage++; | |
| break; | break; |
| } | } |
| break; | break; |
| Line 685 static int yylex(YYSTYPE *lvalp, void *p | Line 755 static int yylex(YYSTYPE *lvalp, void *p |
| } | } |
| break; | break; |
| case '$': | case '$': |
| push_LS(PC, LS_VAR_NAME_SIMPLE); | push_LS(PC, LS_VAR_NAME_SIMPLE_WITH_COLON); |
| RC; | RC; |
| case '^': | case '^': |
| push_LS(PC, LS_METHOD_NAME); | push_LS(PC, LS_METHOD_NAME); |
| Line 740 static int yylex(YYSTYPE *lvalp, void *p | Line 810 static int yylex(YYSTYPE *lvalp, void *p |
| break; | break; |
| case LS_DEF_SPECIAL_BODY: | case LS_DEF_SPECIAL_BODY: |
| // @todo in case | if(c=='\n') |
| // ################ | |
| // @next-method | |
| // we are here with c=='@' | |
| // which is wrong, and need action | |
| if(c=='\n') { | |
| switch(*PC.source) { | |
| case '@': case 0: // end of special_code | |
| pop_LS(PC); | |
| break; | |
| } | |
| RC; | RC; |
| } | |
| break; | break; |
| // (EXPRESSION) | // (EXPRESSION) |
| Line 767 static int yylex(YYSTYPE *lvalp, void *p | Line 826 static int yylex(YYSTYPE *lvalp, void *p |
| pop_LS(PC); // return to normal life | pop_LS(PC); // return to normal life |
| RC; | RC; |
| case '$': | case '$': |
| push_LS(PC, LS_EXPRESSION_VAR_NAME); | push_LS(PC, LS_EXPRESSION_VAR_NAME_WITH_COLON); |
| RC; | RC; |
| case '^': | case '^': |
| push_LS(PC, LS_METHOD_NAME); | push_LS(PC, LS_METHOD_NAME); |
| Line 790 static int yylex(YYSTYPE *lvalp, void *p | Line 849 static int yylex(YYSTYPE *lvalp, void *p |
| goto break2; | goto break2; |
| } | } |
| goto break2; | goto break2; |
| case '+': case '*': case '/': case '%': | case '+': case '*': case '/': case '%': case '\\': |
| case '~': | case '~': |
| case ';': | case ';': |
| RC; | RC; |
| Line 877 static int yylex(YYSTYPE *lvalp, void *p | Line 936 static int yylex(YYSTYPE *lvalp, void *p |
| break; | break; |
| // VARIABLE GET/PUT/WITH | // VARIABLE GET/PUT/WITH |
| case LS_VAR_NAME_SIMPLE: | case LS_VAR_NAME_SIMPLE_WITH_COLON: |
| case LS_EXPRESSION_VAR_NAME: | case LS_VAR_NAME_SIMPLE_WITHOUT_COLON: |
| case LS_VAR_NAME_NO_COLON: | case LS_EXPRESSION_VAR_NAME_WITH_COLON: |
| if(PC.ls==LS_EXPRESSION_VAR_NAME) { | case LS_EXPRESSION_VAR_NAME_WITHOUT_COLON: |
| // name in expr ends also before binary operators | if( |
| PC.ls==LS_EXPRESSION_VAR_NAME_WITH_COLON || | |
| PC.ls==LS_EXPRESSION_VAR_NAME_WITHOUT_COLON) { | |
| // name in expr ends also before | |
| switch(c) { | switch(c) { |
| // expression minus | |
| case '-': | case '-': |
| // expression integer division | |
| case '\\': | |
| pop_LS(PC); | pop_LS(PC); |
| PC.source--; if(--PC.col<0) { PC.line--; PC.col=-1; } | PC.source--; if(--PC.col<0) { PC.line--; PC.col=-1; } |
| result=EON; | result=EON; |
| goto break2; | goto break2; |
| } | } |
| } | } |
| if(PC.ls==LS_VAR_NAME_NO_COLON) { | if( |
| PC.ls==LS_VAR_NAME_SIMPLE_WITHOUT_COLON || | |
| PC.ls==LS_EXPRESSION_VAR_NAME_WITHOUT_COLON) { | |
| // name already has ':', stop before next | // name already has ':', stop before next |
| switch(c) { | switch(c) { |
| case ':': | case ':': |
| Line 911 static int yylex(YYSTYPE *lvalp, void *p | Line 978 static int yylex(YYSTYPE *lvalp, void *p |
| case '&': case '|': | case '&': case '|': |
| case '=': case '!': | case '=': case '!': |
| // common delimiters | // common delimiters |
| case ',': | case ',': case '?': |
| // before call | // before call |
| case '^': | case '^': |
| pop_LS(PC); | pop_LS(PC); |
| Line 919 static int yylex(YYSTYPE *lvalp, void *p | Line 986 static int yylex(YYSTYPE *lvalp, void *p |
| result=EON; | result=EON; |
| goto break2; | goto break2; |
| case '[': | case '[': |
| // $name.<[>code] | |
| if(PC.col>1/*not first column*/ && ( | |
| end[-1]=='$'/*was start of get*/ || | |
| end[-1]==':'/*was class name delim */ || | |
| end[-1]=='.'/*was name delim */ | |
| )) { | |
| push_LS(PC, LS_NAME_SQUARE_PART); | |
| lexical_brackets_nestage=1; | |
| RC; | |
| } | |
| PC.ls=LS_VAR_SQUARE; | PC.ls=LS_VAR_SQUARE; |
| lexical_brackets_nestage=1; | lexical_brackets_nestage=1; |
| RC; | RC; |
| Line 937 static int yylex(YYSTYPE *lvalp, void *p | Line 1014 static int yylex(YYSTYPE *lvalp, void *p |
| RC; | RC; |
| case '.': // name part delim | case '.': // name part delim |
| case '$': // name part subvar | case '$': // name part subvar |
| case ':': // ':name' or 'class:name' | case ':': // class<:>name |
| PC.ls=LS_VAR_NAME_NO_COLON; // stop before next ':' | // go to _WITHOUT_COLON state variant... |
| if(PC.ls==LS_VAR_NAME_SIMPLE_WITH_COLON) | |
| PC.ls=LS_VAR_NAME_SIMPLE_WITHOUT_COLON; | |
| else if(PC.ls==LS_EXPRESSION_VAR_NAME_WITH_COLON) | |
| PC.ls=LS_EXPRESSION_VAR_NAME_WITHOUT_COLON; | |
| // ...stop before next ':' | |
| RC; | RC; |
| } | } |
| break; | break; |
| case LS_VAR_NAME_CURLY: | case LS_VAR_NAME_CURLY: |
| switch(c) { | switch(c) { |
| case '[': | |
| // ${name.<[>code]} | |
| push_LS(PC, LS_NAME_SQUARE_PART); | |
| lexical_brackets_nestage=1; | |
| RC; | |
| case '}': // ${name} finished, restoring LS | case '}': // ${name} finished, restoring LS |
| pop_LS(PC); | pop_LS(PC); |
| RC; | RC; |
| Line 958 static int yylex(YYSTYPE *lvalp, void *p | Line 1045 static int yylex(YYSTYPE *lvalp, void *p |
| case LS_VAR_SQUARE: | case LS_VAR_SQUARE: |
| switch(c) { | switch(c) { |
| case '$': | case '$': |
| push_LS(PC, LS_VAR_NAME_SIMPLE); | push_LS(PC, LS_VAR_NAME_SIMPLE_WITH_COLON); |
| RC; | RC; |
| case '^': | case '^': |
| push_LS(PC, LS_METHOD_NAME); | push_LS(PC, LS_METHOD_NAME); |
| Line 980 static int yylex(YYSTYPE *lvalp, void *p | Line 1067 static int yylex(YYSTYPE *lvalp, void *p |
| case LS_VAR_CURLY: | case LS_VAR_CURLY: |
| switch(c) { | switch(c) { |
| case '$': | case '$': |
| push_LS(PC, LS_VAR_NAME_SIMPLE); | push_LS(PC, LS_VAR_NAME_SIMPLE_WITH_COLON); |
| RC; | RC; |
| case '^': | case '^': |
| push_LS(PC, LS_METHOD_NAME); | push_LS(PC, LS_METHOD_NAME); |
| Line 1001 static int yylex(YYSTYPE *lvalp, void *p | Line 1088 static int yylex(YYSTYPE *lvalp, void *p |
| case LS_METHOD_NAME: | case LS_METHOD_NAME: |
| switch(c) { | switch(c) { |
| case '[': | case '[': |
| // ^name.<[>code].xxx | |
| if(PC.col>1/*not first column*/ && ( | |
| end[-1]=='^'/*was start of call*/ || // never, ^[ is literal... | |
| end[-1]==':'/*was class name delim */ || | |
| end[-1]=='.'/*was name delim */ | |
| )) { | |
| push_LS(PC, LS_NAME_SQUARE_PART); | |
| lexical_brackets_nestage=1; | |
| RC; | |
| } | |
| PC.ls=LS_METHOD_SQUARE; | PC.ls=LS_METHOD_SQUARE; |
| lexical_brackets_nestage=1; | lexical_brackets_nestage=1; |
| RC; | RC; |
| Line 1015 static int yylex(YYSTYPE *lvalp, void *p | Line 1112 static int yylex(YYSTYPE *lvalp, void *p |
| case '.': // name part delim | case '.': // name part delim |
| case '$': // name part subvar | case '$': // name part subvar |
| case ':': // ':name' or 'class:name' | case ':': // ':name' or 'class:name' |
| case '^': // ^abc^xxx wrong. bailing out | |
| case ']': case '}': case ')': // ^abc]}) wrong. bailing out | |
| RC; | RC; |
| } | } |
| break; | break; |
| Line 1022 static int yylex(YYSTYPE *lvalp, void *p | Line 1121 static int yylex(YYSTYPE *lvalp, void *p |
| case LS_METHOD_SQUARE: | case LS_METHOD_SQUARE: |
| switch(c) { | switch(c) { |
| case '$': | case '$': |
| push_LS(PC, LS_VAR_NAME_SIMPLE); | push_LS(PC, LS_VAR_NAME_SIMPLE_WITH_COLON); |
| RC; | RC; |
| case '^': | case '^': |
| push_LS(PC, LS_METHOD_NAME); | push_LS(PC, LS_METHOD_NAME); |
| Line 1044 static int yylex(YYSTYPE *lvalp, void *p | Line 1143 static int yylex(YYSTYPE *lvalp, void *p |
| case LS_METHOD_CURLY: | case LS_METHOD_CURLY: |
| switch(c) { | switch(c) { |
| case '$': | case '$': |
| push_LS(PC, LS_VAR_NAME_SIMPLE); | push_LS(PC, LS_VAR_NAME_SIMPLE_WITH_COLON); |
| RC; | RC; |
| case '^': | case '^': |
| push_LS(PC, LS_METHOD_NAME); | push_LS(PC, LS_METHOD_NAME); |