|
|
| version 1.132, 2001/05/10 12:57:25 | version 1.173.14.1, 2002/01/11 16:53:04 |
|---|---|
| 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$ | $Id$ |
| Line 19 | Line 19 |
| -#: in iis make up specialized Pool object for that | -#: in iis make up specialized Pool object for that |
| */ | */ |
| %{ | |
| #define YYSTYPE Array/*<Operation>*/ * | #define YYSTYPE Array/*<Operation>*/ * |
| #define YYPARSE_PARAM pc | #define YYPARSE_PARAM pc |
| #define YYLEX_PARAM pc | #define YYLEX_PARAM pc |
| Line 28 | Line 27 |
| #define yyerror(msg) real_yyerror((parse_control *)pc, msg) | #define yyerror(msg) real_yyerror((parse_control *)pc, msg) |
| #define YYPRINT(file, type, value) yyprint(file, type, value) | #define YYPRINT(file, type, value) yyprint(file, type, value) |
| #include "pa_config_includes.h" | |
| #include "compile_tools.h" | #include "compile_tools.h" |
| #include "pa_value.h" | #include "pa_value.h" |
| #include "pa_request.h" | #include "pa_request.h" |
| #include "pa_vobject.h" | #include "pa_vobject.h" |
| #include "pa_vdouble.h" | #include "pa_vdouble.h" |
| #include "pa_globals.h" | #include "pa_globals.h" |
| #include "pa_vunknown.h" | #include "pa_vvoid.h" |
| #define SELF_ELEMENT_NAME "self" | #define SELF_ELEMENT_NAME "self" |
| #define USE_CONTROL_METHOD_NAME "USE" | #define USE_CONTROL_METHOD_NAME "USE" |
| #define END_CONTROL_METHOD_NAME "end" | |
| static int real_yyerror(parse_control *pc, char *s); | static int real_yyerror(parse_control *pc, char *s); |
| static void yyprint(FILE *file, int type, YYSTYPE value); | static void yyprint(FILE *file, int type, YYSTYPE value); |
| Line 63 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 103 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 - */ |
| %% | %% |
| all: | all: |
| one_big_piece { | one_big_piece { |
| Method& method=*NEW Method(POOL, | Method& method=*NEW Method(POOL, |
| *main_method_name, | *main_method_name, |
| Line 128 control_method: '@' STRING '\n' | Line 125 control_method: '@' STRING '\n' |
| maybe_control_strings { | maybe_control_strings { |
| const String& command=*LA2S($2); | const String& command=*LA2S($2); |
| YYSTYPE strings_code=$4; | YYSTYPE strings_code=$4; |
| if(command==END_CONTROL_METHOD_NAME && strings_code->size()==0) | |
| break; | |
| if(strings_code->size()<1*2) { | if(strings_code->size()<1*2) { |
| strcpy(PC.error, "@"); | strcpy(PC.error, "@"); |
| strcat(PC.error, command.cstr()); | strcat(PC.error, command.cstr()); |
| Line 137 control_method: '@' STRING '\n' | Line 132 control_method: '@' STRING '\n' |
| YYERROR; | YYERROR; |
| } | } |
| if(command==CLASS_NAME) { | if(command==CLASS_NAME) { |
| if(PC.cclass!=&PC.request->OP) { // already changed from default? | if(PC.cclass->base()) { // already changed from default? |
| strcpy(PC.error, "class already have a name '"); | strcpy(PC.error, "class already have a name '"); |
| strncat(PC.error, PC.cclass->name().cstr(), 100); | strncat(PC.error, PC.cclass->name().cstr(), 100); |
| strcat(PC.error, "'"); | strcat(PC.error, "'"); |
| Line 157 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 240 maybe_codes: empty | codes; | Line 234 maybe_codes: empty | codes; |
| codes: code | codes code { $$=$1; P($$, $2) }; | codes: code | codes code { $$=$1; P($$, $2) }; |
| code: write_string | action; | code: write_string | action; |
| action: get | put | with | call; | action: get | put | call; |
| /* get */ | /* get */ |
| Line 248 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); |
| Line 270 name_without_curly_rdive_read: name_with | Line 263 name_without_curly_rdive_read: name_with |
| } | } |
| /* 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 285 put: '$' name_expr_wdive construct { | Line 273 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); |
| Line 298 name_expr_wdive_write: name_expr_dive_co | Line 286 name_expr_wdive_write: name_expr_dive_co |
| /* skip over... */ | /* skip over... */ |
| diving_code->size()>2?3/*OP_+string+get_element*/:2/*OP_+string*/); | diving_code->size()>2?3/*OP_+string+get_element*/: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_by_code | construct_by_expr; | construct: |
| construct_by_code: '[' any_constructor_code_value ']' { | construct_square |
| $$=$2; /* stack: context, name, value */ | | construct_round |
| | construct_curly | |
| ; | |
| construct_square: '[' any_constructor_code_value ']' { | |
| // stack: context, name | |
| $$=$2; // stack: context, name, value | |
| O($$, OP_CONSTRUCT_VALUE); /* value=pop; name=pop; context=pop; construct(context,name,value) */ | O($$, OP_CONSTRUCT_VALUE); /* value=pop; name=pop; context=pop; construct(context,name,value) */ |
| } | } |
| ; | ; |
| construct_by_expr: '(' expr_value ')' { | construct_round: '(' expr_value ')' { |
| $$=$2; /* stack: context, name, value */ | // stack: context, name |
| O($$, OP_CONSTRUCT_EXPR); /* value=pop; name=pop; context=pop; construct(context,name,value) */ | $$=$2; // stack: context, name, value |
| O($$, OP_CONSTRUCT_EXPR); /* value=pop->as_expr_result; name=pop; context=pop; construct(context,name,value) */ | |
| } | } |
| ; | ; |
| construct_curly: '{' maybe_codes '}' { | |
| // stack: context, name | |
| $$=N(POOL); | |
| CCA($$, $2); /* code=pop; name=pop; context=pop; construct(context,name,junction(code)) */ | |
| }; | |
| any_constructor_code_value: | any_constructor_code_value: |
| unknown_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 341 call: call_value { | Line 341 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: '^' { PC.object_constructor_allowed=true } |
| $$=$2; /* with_xxx,diving code; stack: context,method_junction */ | call_name { PC.object_constructor_allowed=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 + Unknown + 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 VUnknown? | if(!value->is_defined()) // value is VVoid? |
| params_code=0; // ^zzz[] case. don't append lone empty param. | params_code=0; // ^zzz[] case. don't append lone empty param. |
| if(params_code) | if(params_code) |
| P($$, params_code); // filling method_frame.store_params | P($$, params_code); // filling method_frame.store_params |
| Line 391 store_curly_param_part: maybe_codes { | Line 393 store_curly_param_part: maybe_codes { |
| PCA($$, $1); | PCA($$, $1); |
| }; | }; |
| code_param_value: | code_param_value: |
| unknown_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 421 name_advance2: name_expr_value { | Line 423 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 435 name_expr_with_subvar_value: STRING subv | Line 438 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 452 subvar__get_write: '$' subvar_ref_name_r | Line 455 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; | |
| /* with */ | if(!PC.object_constructor_allowed) { |
| strcpy(PC.error, ":: not allowed here"); | |
| with: '$' name_without_curly_rdive '{' maybe_codes '}' { | YYERROR; |
| $$=$2; | } |
| O($$, OP_CREATE_RWPOOL); | O($$, OP_PREPARE_TO_CONSTRUCT_OBJECT); |
| P($$, $4); | |
| O($$, OP_REDUCE_RWPOOL); | |
| O($$, OP_WRITE_VALUE); | |
| }; | }; |
| /* expr */ | /* expr */ |
| expr_value: expr { | expr_value: expr { |
| Line 479 expr: | Line 484 expr: |
| | get_value | | get_value |
| | call_value | | call_value |
| | '"' string_inside_quotes_value '"' { $$ = $2; } | | '"' string_inside_quotes_value '"' { $$ = $2; } |
| | '\'' string_inside_quotes_value '\'' { $$ = $2; } | |
| | '(' 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 494 expr: | Line 501 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 529 write_string: STRING { | Line 537 write_string: STRING { |
| change_string_literal_to_write_string_literal($$=$1) | change_string_literal_to_write_string_literal($$=$1) |
| }; | }; |
| unknown_value: /* empty */ { $$=VL(NEW VUnknown(POOL)) }; | void_value: /* empty */ { $$=VL(NEW VVoid(POOL)) }; |
| empty: /* empty */ { $$=N(POOL) }; | empty: /* empty */ { $$=N(POOL) }; |
| %% | %% |
| Line 570 static int yylex(YYSTYPE *lvalp, void *p | Line 578 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 577 static int yylex(YYSTYPE *lvalp, void *p | Line 586 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_USER) { | |
| push_LS(PC, LS_DEF_NAME); | |
| RC; | |
| } else // @ in first column inside some code | |
| 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 625 static int yylex(YYSTYPE *lvalp, void *p | Line 660 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 638 static int yylex(YYSTYPE *lvalp, void *p | Line 675 static int yylex(YYSTYPE *lvalp, void *p |
| // USER'S = NOT OURS | // USER'S = NOT OURS |
| case LS_USER: | case LS_USER: |
| case LS_NAME_SQUARE_PART: // name.[here].xxx | |
| if(PC.trim_bof) | |
| switch(c) { | |
| case '\n': case ' ': case '\t': | |
| begin=PC.source; | |
| begin_line=PC.line; | |
| continue; // skip it | |
| default: | |
| PC.trim_bof=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 667 static int yylex(YYSTYPE *lvalp, void *p | Line 719 static int yylex(YYSTYPE *lvalp, void *p |
| break; | break; |
| // STRING IN EXPRESSION | // STRING IN EXPRESSION |
| case LS_EXPRESSION_STRING: | case LS_EXPRESSION_STRING_QUOTED: |
| case LS_EXPRESSION_STRING_APOSTROFED: | |
| switch(c) { | switch(c) { |
| case '"': | case '"': |
| pop_LS(PC); //"abc". | case '\'': |
| RC; | if( |
| PC.ls == LS_EXPRESSION_STRING_QUOTED && c=='"' || | |
| PC.ls == LS_EXPRESSION_STRING_APOSTROFED && c=='\'') { | |
| pop_LS(PC); //"abc". | 'abc'. | |
| RC; | |
| } | |
| 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 728 static int yylex(YYSTYPE *lvalp, void *p | Line 787 static int yylex(YYSTYPE *lvalp, void *p |
| break; | break; |
| case LS_DEF_SPECIAL_BODY: | case LS_DEF_SPECIAL_BODY: |
| // @todo in case | |
| // ################ | |
| // @next-method | |
| // we are here with c=='@' | |
| // which is wrong, and need action | |
| if(c=='\n') { | if(c=='\n') { |
| switch(*PC.source) { | switch(*PC.source) { |
| case '@': case 0: // end of special_code | case '@': case 0: // end of special_code |
| Line 750 static int yylex(YYSTYPE *lvalp, void *p | Line 814 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 773 static int yylex(YYSTYPE *lvalp, void *p | Line 837 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 797 static int yylex(YYSTYPE *lvalp, void *p | Line 861 static int yylex(YYSTYPE *lvalp, void *p |
| result=c; | result=c; |
| goto break2; | goto break2; |
| case '"': | case '"': |
| push_LS(PC, LS_EXPRESSION_STRING); | push_LS(PC, LS_EXPRESSION_STRING_QUOTED); |
| RC; | |
| case '\'': | |
| push_LS(PC, LS_EXPRESSION_STRING_APOSTROFED); | |
| RC; | RC; |
| case 'l': case 'g': case 'e': case 'n': | case 'l': case 'g': case 'e': case 'n': |
| if(end==begin) // right after whitespace | if(end==begin) // right after whitespace |
| Line 857 static int yylex(YYSTYPE *lvalp, void *p | Line 924 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: |
| if(PC.ls==LS_EXPRESSION_VAR_NAME) { | case LS_EXPRESSION_VAR_NAME_WITH_COLON: |
| case LS_EXPRESSION_VAR_NAME_WITHOUT_COLON: | |
| if( | |
| PC.ls==LS_EXPRESSION_VAR_NAME_WITH_COLON || | |
| PC.ls==LS_EXPRESSION_VAR_NAME_WITHOUT_COLON) { | |
| // name in expr ends also before binary operators | // name in expr ends also before binary operators |
| switch(c) { | switch(c) { |
| case '-': | case '-': |
| Line 869 static int yylex(YYSTYPE *lvalp, void *p | Line 940 static int yylex(YYSTYPE *lvalp, void *p |
| goto break2; | goto break2; |
| } | } |
| } | } |
| if( | |
| PC.ls==LS_VAR_NAME_SIMPLE_WITHOUT_COLON || | |
| PC.ls==LS_EXPRESSION_VAR_NAME_WITHOUT_COLON) { | |
| // name already has ':', stop before next | |
| switch(c) { | |
| case ':': | |
| pop_LS(PC); | |
| PC.source--; if(--PC.col<0) { PC.line--; PC.col=-1; } | |
| result=EON; | |
| goto break2; | |
| } | |
| } | |
| switch(c) { | switch(c) { |
| case 0: | case 0: |
| case ' ': case '\t': case '\n': | case ' ': case '\t': case '\n': |
| case ';': | case ';': |
| case ']': case '}': case ')': | case ']': case '}': case ')': |
| case '"': case '\'': | case '"': case '\'': |
| case '<': case '>': // these stand for HTML brackets and expression binary ops | case '<': case '>': // these stand for HTML brackets AND expression binary ops |
| case '+': case '*': case '/': case '%': | case '+': case '*': case '/': case '%': |
| case '&': case '|': | case '&': case '|': |
| case '=': case '!': | case '=': case '!': |
| // common delimiters | // common delimiters |
| case ',': | case ',': case '?': |
| // before call | |
| 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; |
| 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 904 static int yylex(YYSTYPE *lvalp, void *p | Line 999 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 |
| // 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 924 static int yylex(YYSTYPE *lvalp, void *p | Line 1030 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 946 static int yylex(YYSTYPE *lvalp, void *p | Line 1052 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 967 static int yylex(YYSTYPE *lvalp, void *p | Line 1073 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 981 static int yylex(YYSTYPE *lvalp, void *p | Line 1097 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 988 static int yylex(YYSTYPE *lvalp, void *p | Line 1106 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 1010 static int yylex(YYSTYPE *lvalp, void *p | Line 1128 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); |
| Line 1061 break2: | Line 1179 break2: |
| if((c=='@' || c==0) && end[-1]=='\n') { // we are before LS_DEF_NAME or EOF? | if((c=='@' || c==0) && end[-1]=='\n') { // we are before LS_DEF_NAME or EOF? |
| // strip last \n | // strip last \n |
| end--; | end--; |
| if(end!=begin && end[-1]=='\n') // allow one empty line before LS_DEF_NAME | |
| end--; | |
| } | } |
| if(end!=begin) { // last piece still alive? | if(end!=begin && PC.ls!=LS_COMMENT) { // last piece still alive and not comment? |
| // append it | // append it |
| PC.string->APPEND_CLEAN(begin, end-begin, PC.file, begin_line/*, start_col*/); | PC.string->APPEND_CLEAN(begin, end-begin, PC.file, begin_line/*, start_col*/); |
| } | } |