Annotation of parser3/src/main/compile.y, revision 1.186.2.1
1.168 parser 1: %{
1.105 paf 2: /** @file
1.106 paf 3: Parser: compiler(lexical parser and grammar).
4:
1.87 paf 5: Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.168 parser 6: Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
1.106 paf 7:
1.186.2.1! paf 8: $Id: compile.y,v 1.186 2002/04/18 11:41:29 paf Exp $
1.88 paf 9: */
10:
1.106 paf 11: /**
12: @todo parser4:
13: - cache compiled code from request to request. to do that...
14: -#: make method definitions, @CLASS, @BASE, @USE instructions,
1.88 paf 15: which would be executed afterwards, and actions
16: now performed at compile time would be delayed to run time.
1.106 paf 17: -#: make cache expiration on time and on disk-change of class source
18: -#: in apache use subpools for compiled class storage
19: -#: in iis make up specialized Pool object for that
1.24 paf 20: */
21:
1.90 paf 22: #define YYSTYPE Array/*<Operation>*/ *
1.9 paf 23: #define YYPARSE_PARAM pc
24: #define YYLEX_PARAM pc
25: #define YYDEBUG 1
1.106 paf 26: #define YYERROR_VERBOSE 1
1.9 paf 27: #define yyerror(msg) real_yyerror((parse_control *)pc, msg)
28: #define YYPRINT(file, type, value) yyprint(file, type, value)
1.1 paf 29:
30: #include "compile_tools.h"
1.8 paf 31: #include "pa_value.h"
1.12 paf 32: #include "pa_request.h"
1.39 paf 33: #include "pa_vobject.h"
1.52 paf 34: #include "pa_vdouble.h"
1.98 paf 35: #include "pa_globals.h"
1.141 parser 36: #include "pa_vvoid.h"
1.39 paf 37:
1.85 paf 38: #define SELF_ELEMENT_NAME "self"
1.97 paf 39: #define USE_CONTROL_METHOD_NAME "USE"
1.1 paf 40:
1.125 paf 41: static int real_yyerror(parse_control *pc, char *s);
1.9 paf 42: static void yyprint(FILE *file, int type, YYSTYPE value);
1.125 paf 43: static int yylex(YYSTYPE *lvalp, void *pc);
1.1 paf 44:
45:
1.8 paf 46: // local convinient inplace typecast & var
1.114 paf 47: #define PC (*(parse_control *)pc)
48: #define POOL (*PC.pool)
1.25 paf 49: #undef NEW
50: #define NEW new(POOL)
1.107 paf 51: #ifndef DOXYGEN
1.1 paf 52: %}
53:
54: %pure_parser
55:
1.13 paf 56: %token EON
1.4 paf 57: %token STRING
1.1 paf 58: %token BOGUS
1.55 paf 59:
1.58 paf 60: %token BAD_STRING_COMPARISON_OPERATOR
1.114 paf 61: %token BAD_HEX_LITERAL
1.171 parser 62: %token BAD_METHOD_DECL_START
1.58 paf 63:
1.59 paf 64: %token LAND "&&"
1.58 paf 65: %token LOR "||"
1.59 paf 66: %token LXOR "##"
1.58 paf 67:
68: %token NLE "<="
69: %token NGE ">="
70: %token NEQ "=="
71: %token NNE "!="
72:
73: %token SLT "lt"
74: %token SGT "gt"
75: %token SLE "le"
76: %token SGE "ge"
77: %token SEQ "eq"
78: %token SNE "ne"
79:
1.67 paf 80: %token DEF "def"
81: %token IN "in"
82: %token FEXISTS "-f"
1.127 paf 83: %token DEXISTS "-d"
1.95 paf 84: %token IS "is"
1.67 paf 85:
1.57 paf 86: /* logical */
1.131 paf 87: %left "##"
1.57 paf 88: %left "||"
89: %left "&&"
1.131 paf 90: %left '<' '>' "<=" ">=" "lt" "gt" "le" "ge"
91: %left "==" "!=" "eq" "ne"
92: %left "is" "def" "in" "-f" "-d"
1.68 paf 93: %left '!'
1.57 paf 94:
95: /* bitwise */
1.59 paf 96: %left '#'
1.131 paf 97: %left '|'
98: %left '&'
1.68 paf 99: %left '~'
1.57 paf 100:
1.56 paf 101: /* numerical */
1.55 paf 102: %left '-' '+'
1.173 paf 103: %left '*' '/' '%' '\\'
1.56 paf 104: %left NEG /* negation: unary - */
1.1 paf 105:
106: %%
1.152 parser 107: all:
1.10 paf 108: one_big_piece {
1.75 paf 109: Method& method=*NEW Method(POOL,
1.186.2.1! paf 110: PC.request->main_method_name,
1.122 paf 111: Method::CT_ANY,
1.81 paf 112: 0, 0, /*min, max numbered_params_count*/
1.75 paf 113: 0/*param_names*/, 0/*local_names*/,
114: $1/*parser_code*/, 0/*native_code*/);
1.186.2.1! paf 115: PC.cclass->add_method(PC.request->main_method_name, method);
1.10 paf 116: }
117: | methods;
118:
119: methods: method | methods method;
120: one_big_piece: maybe_codes;
121:
1.34 paf 122: method: control_method | code_method;
123:
124: control_method: '@' STRING '\n'
1.132 paf 125: maybe_control_strings {
1.120 paf 126: const String& command=*LA2S($2);
1.34 paf 127: YYSTYPE strings_code=$4;
1.37 paf 128: if(strings_code->size()<1*2) {
1.114 paf 129: strcpy(PC.error, "@");
130: strcat(PC.error, command.cstr());
131: strcat(PC.error, " is empty");
1.37 paf 132: YYERROR;
133: }
1.74 paf 134: if(command==CLASS_NAME) {
1.146 parser 135: if(PC.cclass->base()) { // already changed from default?
1.114 paf 136: strcpy(PC.error, "class already have a name '");
137: strncat(PC.error, PC.cclass->name().cstr(), 100);
138: strcat(PC.error, "'");
1.73 paf 139: YYERROR;
140: }
141: if(strings_code->size()==1*2) {
142: // new class' name
1.120 paf 143: const String *name=LA2S(strings_code);
1.73 paf 144: // creating the class
1.114 paf 145: PC.cclass=NEW VClass(POOL);
146: PC.cclass->set_name(*name);
1.73 paf 147: // append to request's classes
1.114 paf 148: PC.request->classes().put(*name, PC.cclass);
1.73 paf 149: } else {
1.114 paf 150: strcpy(PC.error, "@"CLASS_NAME" must contain sole name");
1.34 paf 151: YYERROR;
152: }
1.130 paf 153: } else if(command==USE_CONTROL_METHOD_NAME) {
154: for(int i=0; i<strings_code->size(); i+=2)
1.159 parser 155: PC.request->use_file(*LA2S(strings_code, i));
1.130 paf 156: } else if(command==BASE_NAME) {
1.146 parser 157: if(PC.cclass->base()) { // already changed from default?
1.130 paf 158: strcpy(PC.error, "class already have a base '");
159: strncat(PC.error, PC.cclass->base()->name().cstr(), 100);
160: strcat(PC.error, "'");
161: YYERROR;
162: }
163: if(strings_code->size()==1*2) {
164: const String& base_name=*LA2S(strings_code);
165: VClass *base=static_cast<VClass *>(
166: PC.request->classes().get(base_name));
167: if(!base) {
168: strcpy(PC.error, base_name.cstr());
169: strcat(PC.error, ": undefined class in @"BASE_NAME);
1.73 paf 170: YYERROR;
171: }
1.130 paf 172: // @CLASS == @BASE sanity check
173: if(PC.cclass==base) {
174: strcpy(PC.error, "@"CLASS_NAME" equals @"BASE_NAME);
1.45 paf 175: YYERROR;
1.34 paf 176: }
1.130 paf 177: PC.cclass->set_base(*base);
1.34 paf 178: } else {
1.130 paf 179: strcpy(PC.error, "@"BASE_NAME" must contain sole name");
1.34 paf 180: YYERROR;
181: }
1.130 paf 182: } else {
183: strcpy(PC.error, "'");
184: strncat(PC.error, command.cstr(), MAX_STRING/2);
185: strcat(PC.error, "' invalid special name. valid names are "
186: "'"CLASS_NAME"', '"USE_CONTROL_METHOD_NAME"' and '"BASE_NAME"'");
187: YYERROR;
1.34 paf 188: }
189: };
1.132 paf 190: maybe_control_strings: empty | control_strings;
1.37 paf 191: control_strings: control_string | control_strings control_string { $$=$1; P($$, $2) };
192: control_string: maybe_string '\n';
193: maybe_string: empty | STRING;
1.34 paf 194:
195: code_method: '@' STRING bracketed_maybe_strings maybe_bracketed_strings maybe_comment '\n'
1.10 paf 196: maybe_codes {
1.120 paf 197: const String *name=LA2S($2);
1.10 paf 198:
199: YYSTYPE params_names_code=$3;
1.75 paf 200: Array *params_names=0;
201: if(int size=params_names_code->size()) {
202: params_names=NEW Array(POOL);
203: for(int i=0; i<size; i+=2)
1.120 paf 204: *params_names+=LA2S(params_names_code, i);
1.75 paf 205: }
1.10 paf 206:
207: YYSTYPE locals_names_code=$4;
1.75 paf 208: Array *locals_names=0;
209: if(int size=locals_names_code->size()) {
210: locals_names=NEW Array(POOL);
211: for(int i=0; i<size; i+=2)
1.120 paf 212: *locals_names+=LA2S(locals_names_code, i);
1.75 paf 213: }
1.10 paf 214:
1.76 paf 215: Method& method=*NEW Method(POOL,
216: *name,
1.122 paf 217: Method::CT_ANY,
1.81 paf 218: 0, 0/*min,max numbered_params_count*/,
1.76 paf 219: params_names, locals_names,
220: $7, 0);
1.114 paf 221: PC.cclass->add_method(*name, method);
1.8 paf 222: };
1.10 paf 223:
224: maybe_bracketed_strings: empty | bracketed_maybe_strings;
225: bracketed_maybe_strings: '[' maybe_strings ']' {$$=$2};
226: maybe_strings: empty | strings;
227: strings: STRING | strings ';' STRING { $$=$1; P($$, $3) };
228:
229: maybe_comment: empty | STRING;
1.1 paf 230:
231: /* codes */
232:
1.10 paf 233: maybe_codes: empty | codes;
234:
1.90 paf 235: codes: code | codes code { $$=$1; P($$, $2) };
1.81 paf 236: code: write_string | action;
1.149 parser 237: action: get | put | call;
1.1 paf 238:
239: /* get */
240:
1.64 paf 241: get: get_value {
1.184 paf 242: $$=$1; /* stack: resulting value */
243: changetail_or_append($$,
1.186 paf 244: OP_GET_ELEMENT, false, /*->*/OP_GET_ELEMENT__WRITE,
245: /*or */OP_WRITE_VALUE
1.184 paf 246: ); /* value=pop; wcontext.write(value) */
1.1 paf 247: };
1.163 parser 248: get_value: '$' get_name_value { $$=$2 };
1.64 paf 249: get_name_value: name_without_curly_rdive EON | name_in_curly_rdive;
1.1 paf 250: name_in_curly_rdive: '{' name_without_curly_rdive '}' { $$=$2 };
1.44 paf 251: name_without_curly_rdive:
252: name_without_curly_rdive_read
253: | name_without_curly_rdive_class;
1.19 paf 254: name_without_curly_rdive_read: name_without_curly_rdive_code {
1.25 paf 255: $$=N(POOL);
1.22 paf 256: Array *diving_code=$1;
1.120 paf 257: const String *first_name=LA2S(diving_code);
1.179 paf 258: // self.xxx... -> xxx...
259: // OP_VALUE+string+OP_GET_ELEMENT+... -> OP_WITH_SELF+...
1.85 paf 260: if(first_name && *first_name==SELF_ELEMENT_NAME) {
1.54 paf 261: O($$, OP_WITH_SELF); /* stack: starting context */
1.22 paf 262: P($$, diving_code,
263: /* skip over... */
1.179 paf 264: diving_code->size()>=3?3/*OP_VALUE+string+OP_GET_ELEMENTx*/:2/*OP_+string*/);
1.22 paf 265: } else {
1.54 paf 266: O($$, OP_WITH_READ); /* stack: starting context */
1.179 paf 267:
268: // ^if ELEMENT -> ^if ELEMENT_OR_OPERATOR
269: // OP_VALUE+string+OP_GET_ELEMENT. -> OP_VALUE+string+OP_GET_ELEMENT_OR_OPERATOR.
1.180 paf 270: if(PC.in_call_value && diving_code->size()==3)
1.179 paf 271: diving_code->put_int(2, OP_GET_ELEMENT_OR_OPERATOR);
1.22 paf 272: P($$, diving_code);
273: }
274: /* diving code; stack: current context */
1.1 paf 275: };
1.155 parser 276: name_without_curly_rdive_class: class_prefix name_without_curly_rdive_code { $$=$1; P($$, $2) };
1.19 paf 277: name_without_curly_rdive_code: name_advance2 | name_path name_advance2 { $$=$1; P($$, $2) };
1.1 paf 278:
279: /* put */
280:
1.81 paf 281: put: '$' name_expr_wdive construct {
1.20 paf 282: $$=$2; /* stack: context,name */
1.52 paf 283: P($$, $3); /* stack: context,name,constructor_value */
1.20 paf 284: };
1.44 paf 285: name_expr_wdive:
1.157 parser 286: name_expr_wdive_root
287: | name_expr_wdive_write
1.44 paf 288: | name_expr_wdive_class;
1.157 parser 289: name_expr_wdive_root: name_expr_dive_code {
1.44 paf 290: $$=N(POOL);
1.23 paf 291: Array *diving_code=$1;
1.120 paf 292: const String *first_name=LA2S(diving_code);
1.179 paf 293: // $self.xxx... -> $xxx...
294: // OP_VALUE+string+OP_GET_ELEMENT+... -> OP_WITH_SELF+...
1.85 paf 295: if(first_name && *first_name==SELF_ELEMENT_NAME) {
1.54 paf 296: O($$, OP_WITH_SELF); /* stack: starting context */
1.23 paf 297: P($$, diving_code,
298: /* skip over... */
1.179 paf 299: diving_code->size()>=3?3/*OP_VALUE+string+OP_GET_ELEMENTx*/:2/*OP_+string*/);
1.23 paf 300: } else {
1.157 parser 301: O($$, OP_WITH_ROOT); /* stack: starting context */
1.23 paf 302: P($$, diving_code);
303: }
304: /* diving code; stack: current context */
1.156 parser 305: };
1.157 parser 306: name_expr_wdive_write: '.' name_expr_dive_code {
1.156 parser 307: $$=N(POOL);
1.157 parser 308: O($$, OP_WITH_WRITE); /* stack: starting context */
1.156 parser 309: P($$, $2); /* diving code; stack: context,name */
1.20 paf 310: };
1.155 parser 311: name_expr_wdive_class: class_prefix name_expr_dive_code { $$=$1; P($$, $2) };
1.20 paf 312:
1.149 parser 313: construct:
1.163 parser 314: construct_square
315: | construct_round
316: | construct_curly
1.149 parser 317: ;
318: construct_square: '[' any_constructor_code_value ']' {
319: // stack: context, name
320: $$=$2; // stack: context, name, value
1.81 paf 321: O($$, OP_CONSTRUCT_VALUE); /* value=pop; name=pop; context=pop; construct(context,name,value) */
322: }
323: ;
1.149 parser 324: construct_round: '(' expr_value ')' {
1.182 paf 325: $$=N(POOL);
326: O($$, OP_PREPARE_TO_EXPRESSION);
1.149 parser 327: // stack: context, name
1.182 paf 328: P($$, $2); // stack: context, name, value
1.163 parser 329: O($$, OP_CONSTRUCT_EXPR); /* value=pop->as_expr_result; name=pop; context=pop; construct(context,name,value) */
1.81 paf 330: }
1.52 paf 331: ;
1.149 parser 332: construct_curly: '{' maybe_codes '}' {
333: // stack: context, name
334: $$=N(POOL);
1.186 paf 335: OA($$, OP_CURLY_CODE__CONSTRUCT, $2); /* code=pop; name=pop; context=pop; construct(context,name,junction(code)) */
1.149 parser 336: };
337:
1.55 paf 338: any_constructor_code_value:
1.157 parser 339: void_value /* optimized $var[] case */
1.52 paf 340: | STRING /* optimized $var[STRING] case */
1.55 paf 341: | constructor_code_value /* $var[something complex] */
1.1 paf 342: ;
1.55 paf 343: constructor_code_value: constructor_code {
1.25 paf 344: $$=N(POOL);
1.186 paf 345: OA($$, OP_OBJECT_POOL, $1); /* stack: empty write context */
1.183 paf 346: /* some code that writes to that context */
347: /* context=pop; stack: context.value() */
1.1 paf 348: };
1.55 paf 349: constructor_code: codes__excluding_sole_str_literal;
1.27 paf 350: codes__excluding_sole_str_literal: action | code codes { $$=$1; P($$, $2) };
351:
1.1 paf 352: /* call */
353:
1.66 paf 354: call: call_value {
355: $$=$1; /* stack: value */
1.185 paf 356: changetail_or_append($$,
1.186 paf 357: OP_CALL, true, /*->*/ OP_CALL__WRITE,
358: /*or */OP_WRITE_VALUE); /* value=pop; wcontext.write(value) */
1.66 paf 359: };
1.177 paf 360: call_value: '^' {
1.180 paf 361: PC.in_call_value=true;
1.177 paf 362: }
363: call_name {
1.180 paf 364: PC.in_call_value=false;
1.177 paf 365: }
1.154 parser 366: store_params EON { /* ^field.$method{vasya} */
367: $$=$3; /* with_xxx,diving code; stack: context,method_junction */
1.123 paf 368:
1.154 parser 369: YYSTYPE params_code=$5;
1.186 paf 370: if(params_code->size()==3) { // probably [] case. [OP_VALUE + Void + STORE_PARAM]
1.123 paf 371: if(Value *value=LA2V(params_code)) // it is OP_VALUE + value?
1.140 parser 372: if(!value->is_defined()) // value is VVoid?
1.123 paf 373: params_code=0; // ^zzz[] case. don't append lone empty param.
1.186 paf 374: }
375: /* stack: context, method_junction */
376: OA($$, OP_CALL, params_code); // method_frame=make frame(pop junction); ncontext=pop; call(ncontext,method_frame) stack: value
1.1 paf 377: };
378:
1.43 paf 379: call_name: name_without_curly_rdive;
1.38 paf 380:
1.9 paf 381: store_params: store_param | store_params store_param { $$=$1; P($$, $2) };
1.69 paf 382: store_param:
383: store_square_param
384: | store_round_param
385: | store_curly_param
1.31 paf 386: ;
1.123 paf 387: store_square_param: '[' store_code_param_parts ']' {$$=$2};
1.69 paf 388: store_round_param: '(' store_expr_param_parts ')' {$$=$2};
1.94 paf 389: store_curly_param: '{' store_curly_param_parts '}' {$$=$2};
1.69 paf 390: store_code_param_parts:
391: store_code_param_part
392: | store_code_param_parts ';' store_code_param_part { $$=$1; P($$, $3) }
393: ;
394: store_expr_param_parts:
395: store_expr_param_part
396: | store_expr_param_parts ';' store_expr_param_part { $$=$1; P($$, $3) }
397: ;
1.94 paf 398: store_curly_param_parts:
399: store_curly_param_part
400: | store_curly_param_parts ';' store_curly_param_part { $$=$1; P($$, $3) }
401: ;
1.120 paf 402: store_code_param_part: code_param_value {
1.32 paf 403: $$=$1;
1.54 paf 404: O($$, OP_STORE_PARAM);
1.120 paf 405: };
1.69 paf 406: store_expr_param_part: write_expr_value {
407: $$=N(POOL);
1.186 paf 408: OA($$, OP_EXPR_CODE__STORE_PARAM, $1);
1.69 paf 409: };
1.94 paf 410: store_curly_param_part: maybe_codes {
411: $$=N(POOL);
1.186 paf 412: OA($$, OP_CURLY_CODE__STORE_PARAM, $1);
1.94 paf 413: };
1.120 paf 414: code_param_value:
1.157 parser 415: void_value /* optimized [;...] case */
1.120 paf 416: | STRING /* optimized [STRING] case */
417: | constructor_code_value /* [something complex] */
418: ;
1.90 paf 419: write_expr_value: expr_value {
1.182 paf 420: $$=N(POOL);
421: O($$, OP_PREPARE_TO_EXPRESSION);
422: P($$, $1);
1.102 paf 423: O($$, OP_WRITE_EXPR_RESULT);
1.69 paf 424: };
1.1 paf 425:
426: /* name */
427:
1.20 paf 428: name_expr_dive_code: name_expr_value | name_path name_expr_value { $$=$1; P($$, $2) };
1.1 paf 429:
1.9 paf 430: name_path: name_step | name_path name_step { $$=$1; P($$, $2) };
1.1 paf 431: name_step: name_advance1 '.';
432: name_advance1: name_expr_value {
1.177 paf 433: // we know that name_advance1 not called from ^xxx context
434: // so we'll not check for operator call possibility as we do in name_advance2
435:
1.1 paf 436: /* stack: context */
437: $$=$1; /* stack: context,name */
1.54 paf 438: O($$, OP_GET_ELEMENT); /* name=pop; context=pop; stack: context.get_element(name) */
1.1 paf 439: };
440: name_advance2: name_expr_value {
441: /* stack: context */
442: $$=$1; /* stack: context,name */
1.179 paf 443: O($$, OP_GET_ELEMENT); /* name=pop; context=pop; stack: context.get_element(name) */
1.1 paf 444: }
1.4 paf 445: | STRING BOGUS
1.1 paf 446: ;
447: name_expr_value:
1.4 paf 448: STRING /* subname_is_const */
1.1 paf 449: | name_expr_subvar_value /* $subname_is_var_value */
1.160 parser 450: | name_expr_with_subvar_value /* xxx$part_of_subname_is_var_value */
1.166 parser 451: | name_square_code_value /* [codes] */
1.1 paf 452: ;
453: name_expr_subvar_value: '$' subvar_ref_name_rdive {
454: $$=$2;
1.54 paf 455: O($$, OP_GET_ELEMENT);
1.1 paf 456: };
1.4 paf 457: name_expr_with_subvar_value: STRING subvar_get_writes {
1.183 paf 458: Array *code;
459: {
460: change_string_literal_to_write_string_literal(code=$1);
461: P(code, $2);
462: }
1.25 paf 463: $$=N(POOL);
1.186 paf 464: OA($$, OP_STRING_POOL, code);
1.1 paf 465: };
1.166 parser 466: name_square_code_value: '[' codes ']' {
1.160 parser 467: $$=N(POOL);
1.186 paf 468: OA($$, OP_OBJECT_POOL, $2); /* stack: empty write context */
1.183 paf 469: /* some code that writes to that context */
470: /* context=pop; stack: context.value() */
1.160 parser 471: };
1.154 parser 472: subvar_ref_name_rdive: STRING {
1.25 paf 473: $$=N(POOL);
1.54 paf 474: O($$, OP_WITH_READ);
1.9 paf 475: P($$, $1);
1.1 paf 476: };
1.9 paf 477: subvar_get_writes: subvar__get_write | subvar_get_writes subvar__get_write { $$=$1; P($$, $2) };
1.1 paf 478: subvar__get_write: '$' subvar_ref_name_rdive {
479: $$=$2;
1.54 paf 480: O($$, OP_GET_ELEMENT__WRITE);
1.42 paf 481: };
482:
1.154 parser 483: class_prefix:
484: class_static_prefix
485: | class_constructor_prefix
486: ;
1.155 parser 487: class_static_prefix: STRING ':' {
488: $$=$1; // stack: class name string
489: O($$, OP_GET_CLASS);
490: };
491: class_constructor_prefix: class_static_prefix ':' {
1.154 parser 492: $$=$1;
1.180 paf 493: if(!PC.in_call_value) {
1.154 parser 494: strcpy(PC.error, ":: not allowed here");
495: YYERROR;
496: }
1.155 parser 497: O($$, OP_PREPARE_TO_CONSTRUCT_OBJECT);
1.1 paf 498: };
499:
1.53 paf 500:
1.56 paf 501: /* expr */
1.53 paf 502:
1.81 paf 503: expr_value: expr {
1.182 paf 504: // see OP_PREPARE_TO_EXPRESSION!!
1.81 paf 505: if(($$=$1)->size()==2) // only one string literal in there?
1.62 paf 506: change_string_literal_to_double_literal($$); // make that string literal Double
507: };
1.56 paf 508: expr:
1.62 paf 509: STRING
1.64 paf 510: | get_value
1.66 paf 511: | call_value
1.64 paf 512: | '"' string_inside_quotes_value '"' { $$ = $2; }
1.145 parser 513: | '\'' string_inside_quotes_value '\'' { $$ = $2; }
1.60 paf 514: | '(' expr ')' { $$ = $2; }
515: /* stack: operand // stack: @operand */
516: | '-' expr %prec NEG { $$=$2; O($$, OP_NEG) }
1.166 parser 517: | '+' expr %prec NEG { $$=$2 }
1.68 paf 518: | '~' expr { $$=$2; O($$, OP_INV) }
519: | '!' expr { $$=$2; O($$, OP_NOT) }
520: | "def" expr { $$=$2; O($$, OP_DEF) }
521: | "in" expr { $$=$2; O($$, OP_IN) }
522: | "-f" expr { $$=$2; O($$, OP_FEXISTS) }
1.127 paf 523: | "-d" expr { $$=$2; O($$, OP_DEXISTS) }
1.60 paf 524: /* stack: a,b // stack: a@b */
525: | expr '-' expr { $$=$1; P($$, $3); O($$, OP_SUB) }
526: | expr '+' expr { $$=$1; P($$, $3); O($$, OP_ADD) }
527: | expr '*' expr { $$=$1; P($$, $3); O($$, OP_MUL) }
528: | expr '/' expr { $$=$1; P($$, $3); O($$, OP_DIV) }
529: | expr '%' expr { $$=$1; P($$, $3); O($$, OP_MOD) }
1.173 paf 530: | expr '\\' expr { $$=$1; P($$, $3); O($$, OP_INTDIV) }
1.60 paf 531: | expr '&' expr { $$=$1; P($$, $3); O($$, OP_BIN_AND) }
532: | expr '|' expr { $$=$1; P($$, $3); O($$, OP_BIN_OR) }
533: | expr '#' expr { $$=$1; P($$, $3); O($$, OP_BIN_XOR) }
1.186 paf 534: | expr "&&" expr { $$=$1; OA($$, OP_NESTED_CODE, $3); O($$, OP_LOG_AND) }
535: | expr "||" expr { $$=$1; OA($$, OP_NESTED_CODE, $3); O($$, OP_LOG_OR) }
1.60 paf 536: | expr "##" expr { $$=$1; P($$, $3); O($$, OP_LOG_XOR) }
537: | expr '<' expr { $$=$1; P($$, $3); O($$, OP_NUM_LT) }
538: | expr '>' expr { $$=$1; P($$, $3); O($$, OP_NUM_GT) }
539: | expr "<=" expr { $$=$1; P($$, $3); O($$, OP_NUM_LE) }
540: | expr ">=" expr { $$=$1; P($$, $3); O($$, OP_NUM_GE) }
541: | expr "==" expr { $$=$1; P($$, $3); O($$, OP_NUM_EQ) }
542: | expr "!=" expr { $$=$1; P($$, $3); O($$, OP_NUM_NE) }
1.61 paf 543: | expr "lt" expr { $$=$1; P($$, $3); O($$, OP_STR_LT) }
544: | expr "gt" expr { $$=$1; P($$, $3); O($$, OP_STR_GT) }
545: | expr "le" expr { $$=$1; P($$, $3); O($$, OP_STR_LE) }
546: | expr "ge" expr { $$=$1; P($$, $3); O($$, OP_STR_GE) }
547: | expr "eq" expr { $$=$1; P($$, $3); O($$, OP_STR_EQ) }
548: | expr "ne" expr { $$=$1; P($$, $3); O($$, OP_STR_NE) }
1.95 paf 549: | expr "is" expr { $$=$1; P($$, $3); O($$, OP_IS) }
1.56 paf 550: ;
1.55 paf 551:
1.65 paf 552: string_inside_quotes_value: maybe_codes {
1.64 paf 553: $$=N(POOL);
1.186 paf 554: OA($$, OP_STRING_POOL, $1); /* stack: empty write context */
1.183 paf 555: /* some code that writes to that context */
556: /* context=pop; stack: context.get_string() */
1.53 paf 557: };
1.1 paf 558:
1.27 paf 559: /* basics */
1.1 paf 560:
1.81 paf 561: write_string: STRING {
1.102 paf 562: // optimized from OP_STRING+OP_WRITE_VALUE to OP_STRING__WRITE
1.84 paf 563: change_string_literal_to_write_string_literal($$=$1)
1.54 paf 564: };
565:
1.157 parser 566: void_value: /* empty */ { $$=VL(NEW VVoid(POOL)) };
1.25 paf 567: empty: /* empty */ { $$=N(POOL) };
1.1 paf 568:
569: %%
1.105 paf 570: #endif
1.1 paf 571:
572: /*
573: 000$111(2222)00
574: 000$111{3333}00
1.9 paf 575: $,^: push,=0
1.1 paf 576: 1:( { break=pop
577: 2:( ) pop
578: 3:{ } pop
579:
580: 000^111(2222)4444{33333}4000
1.9 paf 581: $,^: push,=0
1.1 paf 582: 1:( { break=pop
583: 2:( )=4
584: 3:{ }=4
585: 4:[^({]=pop
586: */
587:
1.110 paf 588: static int yylex(YYSTYPE *lvalp, void *pc) {
1.177 paf 589: #define lexical_brackets_nestage PC.brackets_nestages[PC.ls_sp]
1.48 paf 590: #define RC {result=c; goto break2; }
1.1 paf 591:
592: register int c;
593: int result;
594:
1.114 paf 595: if(PC.pending_state) {
596: result=PC.pending_state;
597: PC.pending_state=0;
1.1 paf 598: return result;
599: }
600:
1.114 paf 601: const char *begin=PC.source;
1.91 paf 602: const char *end;
1.114 paf 603: int begin_line=PC.line;
1.67 paf 604: int skip_analized=0;
1.50 paf 605: while(true) {
1.114 paf 606: c=*(end=(PC.source++));
1.166 parser 607: // fprintf(stderr, "\nchar: %c %02X; nestage: %d, sp=%d", c, c, lexical_brackets_nestage, PC.sp);
1.1 paf 608:
1.4 paf 609: if(c=='\n') {
1.114 paf 610: PC.line++;
611: PC.col=0;
1.10 paf 612: } else
1.114 paf 613: PC.col++;
1.73 paf 614:
1.171 parser 615: if(c=='@' && PC.col==0+1) {
1.175 paf 616: if(PC.ls==LS_DEF_SPECIAL_BODY) {
617: // @SPECIAL
618: // ...
619: // @<here =
620: pop_LS(PC); // exiting from LS_DEF_SPECIAL_BODY state
621: } // continuing checks
1.171 parser 622: if(PC.ls==LS_USER) {
623: push_LS(PC, LS_DEF_NAME);
624: RC;
1.175 paf 625: } else // @ in first column inside some code [when could that be?]
1.171 parser 626: result=BAD_METHOD_DECL_START;
627: goto break2;
628: } else if(c=='^')
1.169 parser 629: switch(PC.ls) {
630: case LS_EXPRESSION_VAR_NAME_WITH_COLON:
631: case LS_EXPRESSION_VAR_NAME_WITHOUT_COLON:
632: case LS_VAR_NAME_SIMPLE_WITH_COLON:
633: case LS_VAR_NAME_SIMPLE_WITHOUT_COLON:
634: case LS_VAR_NAME_CURLY:
635: case LS_METHOD_NAME:
636: case LS_COMMENT:
637: case LS_DEF_COMMENT:
638: // no literals in names, please
639: break;
640: default:
1.114 paf 641: switch(*PC.source) {
1.165 parser 642: // ^escaping some punctuators
1.48 paf 643: case '^': case '$': case ';':
1.126 paf 644: case '(': case ')':
1.48 paf 645: case '[': case ']':
646: case '{': case '}':
1.172 parser 647: case '"': case ':':
1.40 paf 648: if(end!=begin) {
649: // append piece till ^
1.121 paf 650: PC.string->APPEND_CLEAN(begin, end-begin, PC.file, begin_line);
1.40 paf 651: }
1.63 paf 652: // reset piece 'begin' position & line
1.164 parser 653: end=begin=PC.source; // ^
1.114 paf 654: begin_line=PC.line;
1.164 parser 655: if(PC.ls==LS_METHOD_AFTER) {
656: pop_LS(PC);
657: result=EON;
1.165 parser 658: skip_analized=-1; // return to ^ afterwards to assure it's literality
1.164 parser 659: goto break2;
660: } else {
661: // skip over _ after ^
662: PC.source++; PC.col++;
663: // skip analysis = forced literal
664: continue;
665: }
1.114 paf 666:
667: // converting ^#HH into char(hex(HH))
668: case '#':
669: if(end!=begin) {
670: // append piece till ^
1.121 paf 671: PC.string->APPEND_CLEAN(begin, end-begin, PC.file, begin_line);
1.114 paf 672: }
673: // #HH ?
674: if(PC.source[0]=='#' && PC.source[1] && PC.source[2]) {
675: char *hex=(char *)POOL.malloc(1);
676: hex[0]=
677: hex_value[(unsigned char)PC.source[1]]*0x10+
678: hex_value[(unsigned char)PC.source[2]];
679: if(hex[0]==0) {
680: result=BAD_HEX_LITERAL;
681: goto break2; // wrong hex value[no ^#00 chars allowed]: bail out
682: }
683: // append char(hex(HH))
1.121 paf 684: PC.string->APPEND_CLEAN(hex, 1, PC.file, begin_line);
1.114 paf 685: // skip over ^#HH
686: PC.source+=3;
687: PC.col+=3;
688: // reset piece 'begin' position & line
689: begin=PC.source; // ^
690: begin_line=PC.line;
691: continue;
692: }
693: break;
1.1 paf 694: }
1.169 parser 695: break;
696: }
1.113 paf 697: // #comment start skipping
1.114 paf 698: if(c=='#' && PC.col==1) {
1.112 paf 699: if(end!=begin) {
700: // append piece till #
1.121 paf 701: PC.string->APPEND_CLEAN(begin, end-begin, PC.file, begin_line);
1.112 paf 702: }
703: // fall into COMMENT lexical state [wait for \n]
704: push_LS(PC, LS_COMMENT);
1.175 paf 705: continue;
1.112 paf 706: }
1.114 paf 707: switch(PC.ls) {
1.10 paf 708:
709: // USER'S = NOT OURS
1.1 paf 710: case LS_USER:
1.166 parser 711: case LS_NAME_SQUARE_PART: // name.[here].xxx
1.153 parser 712: if(PC.trim_bof)
713: switch(c) {
714: case '\n': case ' ': case '\t':
1.152 parser 715: begin=PC.source;
716: begin_line=PC.line;
717: continue; // skip it
1.153 parser 718: default:
719: PC.trim_bof=false;
1.152 parser 720: }
1.48 paf 721: switch(c) {
722: case '$':
1.166 parser 723: push_LS(PC, LS_VAR_NAME_SIMPLE_WITH_COLON);
1.48 paf 724: RC;
725: case '^':
726: push_LS(PC, LS_METHOD_NAME);
727: RC;
1.166 parser 728: case ']':
729: if(PC.ls==LS_NAME_SQUARE_PART)
730: if(--lexical_brackets_nestage==0) {// $name.[co<]?>de<]?>
731: pop_LS(PC); // $name.[co<]>de<]!>
732: RC;
733: }
1.160 parser 734: break;
1.166 parser 735: case '[': // $name.[co<[>de]
736: if(PC.ls==LS_NAME_SQUARE_PART)
737: lexical_brackets_nestage++;
1.161 parser 738: break;
1.112 paf 739: }
740: break;
741:
742: // #COMMENT
743: case LS_COMMENT:
744: if(c=='\n') {
745: // skip comment
1.114 paf 746: begin=PC.source;
747: begin_line=PC.line;
1.112 paf 748:
749: pop_LS(PC);
750: continue;
1.1 paf 751: }
1.48 paf 752: break;
753:
754: // STRING IN EXPRESSION
1.145 parser 755: case LS_EXPRESSION_STRING_QUOTED:
756: case LS_EXPRESSION_STRING_APOSTROFED:
1.48 paf 757: switch(c) {
758: case '"':
1.145 parser 759: case '\'':
760: if(
761: PC.ls == LS_EXPRESSION_STRING_QUOTED && c=='"' ||
762: PC.ls == LS_EXPRESSION_STRING_APOSTROFED && c=='\'') {
763: pop_LS(PC); //"abc". | 'abc'.
764: RC;
765: }
766: break;
1.48 paf 767: case '$':
1.166 parser 768: push_LS(PC, LS_VAR_NAME_SIMPLE_WITH_COLON);
1.48 paf 769: RC;
770: case '^':
1.10 paf 771: push_LS(PC, LS_METHOD_NAME);
1.48 paf 772: RC;
1.10 paf 773: }
774: break;
775:
776: // METHOD DEFINITION
777: case LS_DEF_NAME:
1.48 paf 778: switch(c) {
779: case '[':
1.114 paf 780: PC.ls=LS_DEF_PARAMS;
1.48 paf 781: RC;
782: case '\n':
1.114 paf 783: PC.ls=LS_DEF_SPECIAL_BODY;
1.48 paf 784: RC;
1.10 paf 785: }
786: break;
1.48 paf 787:
1.10 paf 788: case LS_DEF_PARAMS:
1.48 paf 789: switch(c) {
790: case ';':
791: RC;
792: case ']':
1.114 paf 793: PC.ls=*PC.source=='['?LS_DEF_LOCALS:LS_DEF_COMMENT;
1.48 paf 794: RC;
1.49 paf 795: case '\n': // wrong. bailing out
1.10 paf 796: pop_LS(PC);
1.48 paf 797: RC;
1.10 paf 798: }
799: break;
1.48 paf 800:
1.10 paf 801: case LS_DEF_LOCALS:
1.48 paf 802: switch(c) {
803: case '[':
804: case ';':
805: RC;
806: case ']':
1.114 paf 807: PC.ls=LS_DEF_COMMENT;
1.48 paf 808: RC;
809: case '\n': // wrong. bailing out
1.10 paf 810: pop_LS(PC);
1.48 paf 811: RC;
1.10 paf 812: }
813: break;
1.48 paf 814:
1.10 paf 815: case LS_DEF_COMMENT:
816: if(c=='\n') {
817: pop_LS(PC);
1.48 paf 818: RC;
1.37 paf 819: }
820: break;
821:
1.48 paf 822: case LS_DEF_SPECIAL_BODY:
1.175 paf 823: if(c=='\n')
1.48 paf 824: RC;
825: break;
826:
827: // (EXPRESSION)
1.69 paf 828: case LS_VAR_ROUND:
829: case LS_METHOD_ROUND:
1.48 paf 830: switch(c) {
831: case ')':
832: if(--lexical_brackets_nestage==0)
1.114 paf 833: if(PC.ls==LS_METHOD_ROUND) // method round param ended
834: PC.ls=LS_METHOD_AFTER; // look for method end
835: else // PC.ls==LS_VAR_ROUND // variable constructor ended
1.69 paf 836: pop_LS(PC); // return to normal life
1.48 paf 837: RC;
838: case '$':
1.166 parser 839: push_LS(PC, LS_EXPRESSION_VAR_NAME_WITH_COLON);
1.48 paf 840: RC;
841: case '^':
842: push_LS(PC, LS_METHOD_NAME);
843: RC;
844: case '(':
845: lexical_brackets_nestage++;
846: RC;
1.67 paf 847: case '-':
1.127 paf 848: switch(*PC.source) {
849: case 'f': // -f
1.67 paf 850: skip_analized=1;
851: result=FEXISTS;
1.127 paf 852: goto break2;
853: case 'd': // -d
854: skip_analized=1;
855: result=DEXISTS;
856: goto break2;
857: default:
1.67 paf 858: result=c;
1.127 paf 859: goto break2;
860: }
1.67 paf 861: goto break2;
1.173 paf 862: case '+': case '*': case '/': case '%': case '\\':
1.58 paf 863: case '~':
1.48 paf 864: case ';':
865: RC;
1.59 paf 866: case '&': case '|': case '#':
1.114 paf 867: if(*PC.source==c) { // && ||
1.59 paf 868: result=c=='#'?LXOR:c=='&'?LAND:LOR;
1.67 paf 869: skip_analized=1;
1.58 paf 870: } else
871: result=c;
872: goto break2;
873: case '<': case '>': case '=': case '!':
1.114 paf 874: if(*PC.source=='=') { // <= >= == !=
1.67 paf 875: skip_analized=1;
1.58 paf 876: switch(c) {
877: case '<': result=NLE; break;
878: case '>': result=NGE; break;
879: case '=': result=NEQ; break;
880: case '!': result=NNE; break;
881: }
882: } else
883: result=c;
884: goto break2;
1.48 paf 885: case '"':
1.145 parser 886: push_LS(PC, LS_EXPRESSION_STRING_QUOTED);
887: RC;
888: case '\'':
889: push_LS(PC, LS_EXPRESSION_STRING_APOSTROFED);
1.48 paf 890: RC;
1.50 paf 891: case 'l': case 'g': case 'e': case 'n':
1.51 paf 892: if(end==begin) // right after whitespace
1.117 paf 893: if(isspace(PC.source[1])) {
894: switch(*PC.source) {
895: // case '?': // ok [and bad cases, yacc would bark at them]
896: case 't': // lt gt [et nt]
897: result=c=='l'?SLT:c=='g'?SGT:BAD_STRING_COMPARISON_OPERATOR;
898: skip_analized=1;
899: goto break2;
900: case 'e': // le ge ne [ee]
901: result=c=='l'?SLE:c=='g'?SGE:c=='n'?SNE:BAD_STRING_COMPARISON_OPERATOR;
902: skip_analized=1;
903: goto break2;
904: case 'q': // eq [lq gq nq]
905: result=c=='e'?SEQ:BAD_STRING_COMPARISON_OPERATOR;
906: skip_analized=1;
907: goto break2;
908: }
1.67 paf 909: }
910: break;
911: case 'i':
912: if(end==begin) // right after whitespace
1.117 paf 913: if(isspace(PC.source[1])) {
914: switch(PC.source[0]) {
915: case 'n': // in
1.95 paf 916: skip_analized=1;
917: result=IN;
918: goto break2;
1.117 paf 919: case 's': // is
1.95 paf 920: skip_analized=1;
921: result=IS;
922: goto break2;
923: }
1.67 paf 924: }
925: break;
926: case 'd':
927: if(end==begin) // right after whitespace
1.114 paf 928: if(PC.source[0]=='e' && PC.source[1]=='f') { // def
1.67 paf 929: skip_analized=2;
930: result=DEF;
1.58 paf 931: goto break2;
1.50 paf 932: }
1.48 paf 933: break;
934: case ' ': case '\t': case '\n':
1.63 paf 935: if(end!=begin) { // there were a string after previous operator?
936: result=0; // return that string
937: goto break2;
1.48 paf 938: }
1.63 paf 939: // that's a leading|traling space or after-operator-space
940: // ignoring it
941: // reset piece 'begin' position & line
1.114 paf 942: begin=PC.source; // after whitespace char
943: begin_line=PC.line;
1.48 paf 944: continue;
1.1 paf 945: }
946: break;
947:
1.10 paf 948: // VARIABLE GET/PUT/WITH
1.166 parser 949: case LS_VAR_NAME_SIMPLE_WITH_COLON:
950: case LS_VAR_NAME_SIMPLE_WITHOUT_COLON:
951: case LS_EXPRESSION_VAR_NAME_WITH_COLON:
952: case LS_EXPRESSION_VAR_NAME_WITHOUT_COLON:
953: if(
954: PC.ls==LS_EXPRESSION_VAR_NAME_WITH_COLON ||
955: PC.ls==LS_EXPRESSION_VAR_NAME_WITHOUT_COLON) {
1.181 paf 956: // name in expr ends also before
1.48 paf 957: switch(c) {
1.181 paf 958: // expression minus
1.92 paf 959: case '-':
1.181 paf 960: // expression integer division
961: case '\\':
1.48 paf 962: pop_LS(PC);
1.114 paf 963: PC.source--; if(--PC.col<0) { PC.line--; PC.col=-1; }
1.48 paf 964: result=EON;
965: goto break2;
966: }
967: }
1.166 parser 968: if(
969: PC.ls==LS_VAR_NAME_SIMPLE_WITHOUT_COLON ||
970: PC.ls==LS_EXPRESSION_VAR_NAME_WITHOUT_COLON) {
1.142 parser 971: // name already has ':', stop before next
972: switch(c) {
973: case ':':
974: pop_LS(PC);
975: PC.source--; if(--PC.col<0) { PC.line--; PC.col=-1; }
976: result=EON;
977: goto break2;
978: }
979: }
1.48 paf 980: switch(c) {
981: case 0:
982: case ' ': case '\t': case '\n':
983: case ';':
1.126 paf 984: case ']': case '}': case ')':
985: case '"': case '\'':
1.139 parser 986: case '<': case '>': // these stand for HTML brackets AND expression binary ops
1.92 paf 987: case '+': case '*': case '/': case '%':
988: case '&': case '|':
989: case '=': case '!':
1.99 paf 990: // common delimiters
1.158 parser 991: case ',': case '?':
1.139 parser 992: // before call
993: case '^':
1.1 paf 994: pop_LS(PC);
1.114 paf 995: PC.source--; if(--PC.col<0) { PC.line--; PC.col=-1; }
1.13 paf 996: result=EON;
1.1 paf 997: goto break2;
1.48 paf 998: case '[':
1.162 parser 999: // $name.<[>code]
1000: if(PC.col>1/*not first column*/ && (
1.163 parser 1001: end[-1]=='$'/*was start of get*/ ||
1002: end[-1]==':'/*was class name delim */ ||
1003: end[-1]=='.'/*was name delim */
1.162 parser 1004: )) {
1.166 parser 1005: push_LS(PC, LS_NAME_SQUARE_PART);
1.162 parser 1006: lexical_brackets_nestage=1;
1007: RC;
1008: }
1.114 paf 1009: PC.ls=LS_VAR_SQUARE;
1.1 paf 1010: lexical_brackets_nestage=1;
1.48 paf 1011: RC;
1012: case '{':
1013: if(begin==end) { // ${name}, no need of EON, switching LS
1.114 paf 1014: PC.ls=LS_VAR_NAME_CURLY;
1.48 paf 1015: } else {
1.114 paf 1016: PC.ls=LS_VAR_CURLY;
1.48 paf 1017: lexical_brackets_nestage=1;
1018: }
1.69 paf 1019:
1.48 paf 1020: RC;
1021: case '(':
1.114 paf 1022: PC.ls=LS_VAR_ROUND;
1.1 paf 1023: lexical_brackets_nestage=1;
1.48 paf 1024: RC;
1025: case '.': // name part delim
1026: case '$': // name part subvar
1.160 parser 1027: case ':': // class<:>name
1.166 parser 1028: // go to _WITHOUT_COLON state variant...
1029: if(PC.ls==LS_VAR_NAME_SIMPLE_WITH_COLON)
1030: PC.ls=LS_VAR_NAME_SIMPLE_WITHOUT_COLON;
1031: else if(PC.ls==LS_EXPRESSION_VAR_NAME_WITH_COLON)
1032: PC.ls=LS_EXPRESSION_VAR_NAME_WITHOUT_COLON;
1033: // ...stop before next ':'
1.48 paf 1034: RC;
1.1 paf 1035: }
1036: break;
1.48 paf 1037:
1.1 paf 1038: case LS_VAR_NAME_CURLY:
1.48 paf 1039: switch(c) {
1.162 parser 1040: case '[':
1.166 parser 1041: // ${name.<[>code]}
1042: push_LS(PC, LS_NAME_SQUARE_PART);
1.160 parser 1043: lexical_brackets_nestage=1;
1044: RC;
1.48 paf 1045: case '}': // ${name} finished, restoring LS
1.1 paf 1046: pop_LS(PC);
1.48 paf 1047: RC;
1048: case '.': // name part delim
1049: case '$': // name part subvar
1050: case ':': // ':name' or 'class:name'
1051: RC;
1.1 paf 1052: }
1053: break;
1.48 paf 1054:
1055: case LS_VAR_SQUARE:
1056: switch(c) {
1057: case '$':
1.166 parser 1058: push_LS(PC, LS_VAR_NAME_SIMPLE_WITH_COLON);
1.48 paf 1059: RC;
1060: case '^':
1.10 paf 1061: push_LS(PC, LS_METHOD_NAME);
1.48 paf 1062: RC;
1063: case ']':
1.1 paf 1064: if(--lexical_brackets_nestage==0) {
1065: pop_LS(PC);
1.48 paf 1066: RC;
1.1 paf 1067: }
1.48 paf 1068: break;
1069: case ';': // operator_or_fmt;value delim
1070: RC;
1071: case '[':
1072: lexical_brackets_nestage++;
1073: break;
1.1 paf 1074: }
1075: break;
1.48 paf 1076:
1.1 paf 1077: case LS_VAR_CURLY:
1.48 paf 1078: switch(c) {
1079: case '$':
1.166 parser 1080: push_LS(PC, LS_VAR_NAME_SIMPLE_WITH_COLON);
1.48 paf 1081: RC;
1082: case '^':
1.10 paf 1083: push_LS(PC, LS_METHOD_NAME);
1.48 paf 1084: RC;
1085: case '}':
1.1 paf 1086: if(--lexical_brackets_nestage==0) {
1087: pop_LS(PC);
1.48 paf 1088: RC;
1.1 paf 1089: }
1.48 paf 1090: break;
1091: case '{':
1.1 paf 1092: lexical_brackets_nestage++;
1.48 paf 1093: break;
1094: }
1.1 paf 1095: break;
1096:
1.10 paf 1097: // METHOD CALL
1.1 paf 1098: case LS_METHOD_NAME:
1.48 paf 1099: switch(c) {
1100: case '[':
1.166 parser 1101: // ^name.<[>code].xxx
1.162 parser 1102: if(PC.col>1/*not first column*/ && (
1.163 parser 1103: end[-1]=='^'/*was start of call*/ || // never, ^[ is literal...
1104: end[-1]==':'/*was class name delim */ ||
1105: end[-1]=='.'/*was name delim */
1.162 parser 1106: )) {
1.166 parser 1107: push_LS(PC, LS_NAME_SQUARE_PART);
1.162 parser 1108: lexical_brackets_nestage=1;
1109: RC;
1110: }
1.114 paf 1111: PC.ls=LS_METHOD_SQUARE;
1.1 paf 1112: lexical_brackets_nestage=1;
1.48 paf 1113: RC;
1114: case '{':
1.114 paf 1115: PC.ls=LS_METHOD_CURLY;
1.1 paf 1116: lexical_brackets_nestage=1;
1.48 paf 1117: RC;
1.69 paf 1118: case '(':
1.114 paf 1119: PC.ls=LS_METHOD_ROUND;
1.69 paf 1120: lexical_brackets_nestage=1;
1121: RC;
1.48 paf 1122: case '.': // name part delim
1123: case '$': // name part subvar
1124: case ':': // ':name' or 'class:name'
1.170 parser 1125: case '^': // ^abc^xxx wrong. bailing out
1126: case ']': case '}': case ')': // ^abc]}) wrong. bailing out
1.48 paf 1127: RC;
1.1 paf 1128: }
1129: break;
1.48 paf 1130:
1131: case LS_METHOD_SQUARE:
1132: switch(c) {
1133: case '$':
1.166 parser 1134: push_LS(PC, LS_VAR_NAME_SIMPLE_WITH_COLON);
1.48 paf 1135: RC;
1136: case '^':
1.10 paf 1137: push_LS(PC, LS_METHOD_NAME);
1.48 paf 1138: RC;
1139: case ';': // param delim
1140: RC;
1141: case ']':
1.1 paf 1142: if(--lexical_brackets_nestage==0) {
1.114 paf 1143: PC.ls=LS_METHOD_AFTER;
1.48 paf 1144: RC;
1.1 paf 1145: }
1.48 paf 1146: break;
1147: case '[':
1.1 paf 1148: lexical_brackets_nestage++;
1.48 paf 1149: break;
1150: }
1.1 paf 1151: break;
1.48 paf 1152:
1.1 paf 1153: case LS_METHOD_CURLY:
1.48 paf 1154: switch(c) {
1155: case '$':
1.166 parser 1156: push_LS(PC, LS_VAR_NAME_SIMPLE_WITH_COLON);
1.48 paf 1157: RC;
1158: case '^':
1.10 paf 1159: push_LS(PC, LS_METHOD_NAME);
1.94 paf 1160: RC;
1161: case ';': // param delim
1.48 paf 1162: RC;
1163: case '}':
1.1 paf 1164: if(--lexical_brackets_nestage==0) {
1.114 paf 1165: PC.ls=LS_METHOD_AFTER;
1.48 paf 1166: RC;
1.1 paf 1167: }
1.48 paf 1168: break;
1169: case '{':
1.1 paf 1170: lexical_brackets_nestage++;
1.48 paf 1171: break;
1172: }
1.1 paf 1173: break;
1.48 paf 1174:
1.1 paf 1175: case LS_METHOD_AFTER:
1.69 paf 1176: if(c=='[') {/* ][ }[ )[ */
1.114 paf 1177: PC.ls=LS_METHOD_SQUARE;
1.1 paf 1178: lexical_brackets_nestage=1;
1.48 paf 1179: RC;
1.1 paf 1180: }
1.69 paf 1181: if(c=='{') {/* ]{ }{ ){ */
1.114 paf 1182: PC.ls=LS_METHOD_CURLY;
1.69 paf 1183: lexical_brackets_nestage=1;
1184: RC;
1185: }
1186: if(c=='(') {/* ]( }( )( */
1.114 paf 1187: PC.ls=LS_METHOD_ROUND;
1.1 paf 1188: lexical_brackets_nestage=1;
1.48 paf 1189: RC;
1.1 paf 1190: }
1191: pop_LS(PC);
1.114 paf 1192: PC.source--; if(--PC.col<0) { PC.line--; PC.col=-1; }
1.13 paf 1193: result=EON;
1.1 paf 1194: goto break2;
1195: }
1.9 paf 1196: if(c==0) {
1.1 paf 1197: result=-1;
1198: break;
1199: }
1200: }
1201:
1202: break2:
1.59 paf 1203: if(end!=begin) { // there is last piece?
1204: if((c=='@' || c==0) && end[-1]=='\n') { // we are before LS_DEF_NAME or EOF?
1205: // strip last \n
1.10 paf 1206: end--;
1.137 parser 1207: if(end!=begin && end[-1]=='\n') // allow one empty line before LS_DEF_NAME
1208: end--;
1.59 paf 1209: }
1.133 parser 1210: if(end!=begin && PC.ls!=LS_COMMENT) { // last piece still alive and not comment?
1.59 paf 1211: // append it
1.121 paf 1212: PC.string->APPEND_CLEAN(begin, end-begin, PC.file, begin_line/*, start_col*/);
1.30 paf 1213: }
1.59 paf 1214: }
1.114 paf 1215: if(PC.string->size()) { // something accumulated?
1.17 paf 1216: // create STRING value: array of OP_VALUE+vstring
1.114 paf 1217: *lvalp=VL(NEW VString(*PC.string));
1.10 paf 1218: // new pieces storage
1.114 paf 1219: PC.string=NEW String(POOL);
1.58 paf 1220: // make current result be pending for next call, return STRING for now
1.114 paf 1221: PC.pending_state=result; result=STRING;
1.58 paf 1222: }
1.67 paf 1223: if(skip_analized) {
1.114 paf 1224: PC.source+=skip_analized; PC.col+=skip_analized;
1.1 paf 1225: }
1.58 paf 1226: return result;
1.1 paf 1227: }
1228:
1.110 paf 1229: static int real_yyerror(parse_control *pc, char *s) { // Called by yyparse on error
1.114 paf 1230: strncpy(PC.error, s, MAX_STRING);
1.1 paf 1231: return 1;
1.110 paf 1232: }
1.1 paf 1233:
1.110 paf 1234: static void yyprint(FILE *file, int type, YYSTYPE value) {
1235: if(type==STRING)
1.120 paf 1236: fprintf(file, " \"%s\"", LA2S(value)->cstr());
1.110 paf 1237: }
E-mail: