Annotation of parser3/src/main/compile.y, revision 1.172
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.172 ! parser 8: $Id: compile.y,v 1.171 2001/10/10 12:41:29 parser 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.57 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.85 paf 110: *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.114 paf 115: PC.cclass->add_method(*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 {
242: $$=$1; /* stack: resulting value */
1.102 paf 243: O($$, OP_WRITE_VALUE); /* value=pop; wcontext.write(value) */
1.1 paf 244: };
1.163 parser 245: get_value: '$' get_name_value { $$=$2 };
1.64 paf 246: get_name_value: name_without_curly_rdive EON | name_in_curly_rdive;
1.1 paf 247: name_in_curly_rdive: '{' name_without_curly_rdive '}' { $$=$2 };
1.44 paf 248: name_without_curly_rdive:
249: name_without_curly_rdive_read
250: | name_without_curly_rdive_class;
1.19 paf 251: name_without_curly_rdive_read: name_without_curly_rdive_code {
1.25 paf 252: $$=N(POOL);
1.22 paf 253: Array *diving_code=$1;
1.120 paf 254: const String *first_name=LA2S(diving_code);
1.85 paf 255: if(first_name && *first_name==SELF_ELEMENT_NAME) {
1.54 paf 256: O($$, OP_WITH_SELF); /* stack: starting context */
1.22 paf 257: P($$, diving_code,
258: /* skip over... */
259: diving_code->size()>2?3/*OP_+string+get_element*/:2/*OP_+string*/);
260: } else {
1.54 paf 261: O($$, OP_WITH_READ); /* stack: starting context */
1.22 paf 262: P($$, diving_code);
263: }
264: /* diving code; stack: current context */
1.1 paf 265: };
1.155 parser 266: name_without_curly_rdive_class: class_prefix name_without_curly_rdive_code { $$=$1; P($$, $2) };
1.19 paf 267: name_without_curly_rdive_code: name_advance2 | name_path name_advance2 { $$=$1; P($$, $2) };
1.1 paf 268:
269: /* put */
270:
1.81 paf 271: put: '$' name_expr_wdive construct {
1.20 paf 272: $$=$2; /* stack: context,name */
1.52 paf 273: P($$, $3); /* stack: context,name,constructor_value */
1.20 paf 274: };
1.44 paf 275: name_expr_wdive:
1.157 parser 276: name_expr_wdive_root
277: | name_expr_wdive_write
1.44 paf 278: | name_expr_wdive_class;
1.157 parser 279: name_expr_wdive_root: name_expr_dive_code {
1.44 paf 280: $$=N(POOL);
1.23 paf 281: Array *diving_code=$1;
1.120 paf 282: const String *first_name=LA2S(diving_code);
1.85 paf 283: if(first_name && *first_name==SELF_ELEMENT_NAME) {
1.54 paf 284: O($$, OP_WITH_SELF); /* stack: starting context */
1.23 paf 285: P($$, diving_code,
286: /* skip over... */
287: diving_code->size()>2?3/*OP_+string+get_element*/:2/*OP_+string*/);
288: } else {
1.157 parser 289: O($$, OP_WITH_ROOT); /* stack: starting context */
1.23 paf 290: P($$, diving_code);
291: }
292: /* diving code; stack: current context */
1.156 parser 293: };
1.157 parser 294: name_expr_wdive_write: '.' name_expr_dive_code {
1.156 parser 295: $$=N(POOL);
1.157 parser 296: O($$, OP_WITH_WRITE); /* stack: starting context */
1.156 parser 297: P($$, $2); /* diving code; stack: context,name */
1.20 paf 298: };
1.155 parser 299: name_expr_wdive_class: class_prefix name_expr_dive_code { $$=$1; P($$, $2) };
1.20 paf 300:
1.149 parser 301: construct:
1.163 parser 302: construct_square
303: | construct_round
304: | construct_curly
1.149 parser 305: ;
306: construct_square: '[' any_constructor_code_value ']' {
307: // stack: context, name
308: $$=$2; // stack: context, name, value
1.81 paf 309: O($$, OP_CONSTRUCT_VALUE); /* value=pop; name=pop; context=pop; construct(context,name,value) */
310: }
311: ;
1.149 parser 312: construct_round: '(' expr_value ')' {
313: // stack: context, name
314: $$=$2; // stack: context, name, value
1.163 parser 315: O($$, OP_CONSTRUCT_EXPR); /* value=pop->as_expr_result; name=pop; context=pop; construct(context,name,value) */
1.81 paf 316: }
1.52 paf 317: ;
1.149 parser 318: construct_curly: '{' maybe_codes '}' {
319: // stack: context, name
320: $$=N(POOL);
321: CCA($$, $2); /* code=pop; name=pop; context=pop; construct(context,name,junction(code)) */
322: };
323:
1.55 paf 324: any_constructor_code_value:
1.157 parser 325: void_value /* optimized $var[] case */
1.52 paf 326: | STRING /* optimized $var[STRING] case */
1.55 paf 327: | constructor_code_value /* $var[something complex] */
1.1 paf 328: ;
1.55 paf 329: constructor_code_value: constructor_code {
1.25 paf 330: $$=N(POOL);
1.54 paf 331: O($$, OP_CREATE_EWPOOL); /* stack: empty write context */
1.69 paf 332: P($$, $1); /* some code that writes to that context */
1.54 paf 333: O($$, OP_REDUCE_EWPOOL); /* context=pop; stack: context.value() */
1.1 paf 334: };
1.55 paf 335: constructor_code: codes__excluding_sole_str_literal;
1.27 paf 336: codes__excluding_sole_str_literal: action | code codes { $$=$1; P($$, $2) };
337:
1.1 paf 338: /* call */
339:
1.66 paf 340: call: call_value {
341: $$=$1; /* stack: value */
1.102 paf 342: O($$, OP_WRITE_VALUE); /* value=pop; wcontext.write(value) */
1.66 paf 343: };
1.154 parser 344: call_value: '^' { PC.object_constructor_allowed=true }
345: call_name { PC.object_constructor_allowed=false }
346: store_params EON { /* ^field.$method{vasya} */
347: $$=$3; /* with_xxx,diving code; stack: context,method_junction */
1.54 paf 348: O($$, OP_GET_METHOD_FRAME); /* stack: context,method_frame */
1.123 paf 349:
1.154 parser 350: YYSTYPE params_code=$5;
1.140 parser 351: if(params_code->size()==3) // probably [] case. [OP_VALUE + Void + STORE_PARAM]
1.123 paf 352: if(Value *value=LA2V(params_code)) // it is OP_VALUE + value?
1.140 parser 353: if(!value->is_defined()) // value is VVoid?
1.123 paf 354: params_code=0; // ^zzz[] case. don't append lone empty param.
355: if(params_code)
356: P($$, params_code); // filling method_frame.store_params
1.155 parser 357: O($$, OP_CALL); // method_frame=pop; ncontext=pop; call(ncontext,method_frame) stack: value
1.1 paf 358: };
359:
1.43 paf 360: call_name: name_without_curly_rdive;
1.38 paf 361:
1.9 paf 362: store_params: store_param | store_params store_param { $$=$1; P($$, $2) };
1.69 paf 363: store_param:
364: store_square_param
365: | store_round_param
366: | store_curly_param
1.31 paf 367: ;
1.123 paf 368: store_square_param: '[' store_code_param_parts ']' {$$=$2};
1.69 paf 369: store_round_param: '(' store_expr_param_parts ')' {$$=$2};
1.94 paf 370: store_curly_param: '{' store_curly_param_parts '}' {$$=$2};
1.69 paf 371: store_code_param_parts:
372: store_code_param_part
373: | store_code_param_parts ';' store_code_param_part { $$=$1; P($$, $3) }
374: ;
375: store_expr_param_parts:
376: store_expr_param_part
377: | store_expr_param_parts ';' store_expr_param_part { $$=$1; P($$, $3) }
378: ;
1.94 paf 379: store_curly_param_parts:
380: store_curly_param_part
381: | store_curly_param_parts ';' store_curly_param_part { $$=$1; P($$, $3) }
382: ;
1.120 paf 383: store_code_param_part: code_param_value {
1.32 paf 384: $$=$1;
1.54 paf 385: O($$, OP_STORE_PARAM);
1.120 paf 386: };
1.69 paf 387: store_expr_param_part: write_expr_value {
388: $$=N(POOL);
1.103 paf 389: PEA($$, $1);
1.69 paf 390: };
1.94 paf 391: store_curly_param_part: maybe_codes {
392: $$=N(POOL);
393: PCA($$, $1);
394: };
1.120 paf 395: code_param_value:
1.157 parser 396: void_value /* optimized [;...] case */
1.120 paf 397: | STRING /* optimized [STRING] case */
398: | constructor_code_value /* [something complex] */
399: ;
1.90 paf 400: write_expr_value: expr_value {
1.69 paf 401: $$=$1;
1.102 paf 402: O($$, OP_WRITE_EXPR_RESULT);
1.69 paf 403: };
1.1 paf 404:
405: /* name */
406:
1.20 paf 407: name_expr_dive_code: name_expr_value | name_path name_expr_value { $$=$1; P($$, $2) };
1.1 paf 408:
1.9 paf 409: name_path: name_step | name_path name_step { $$=$1; P($$, $2) };
1.1 paf 410: name_step: name_advance1 '.';
411: name_advance1: name_expr_value {
412: /* stack: context */
413: $$=$1; /* stack: context,name */
1.54 paf 414: O($$, OP_GET_ELEMENT); /* name=pop; context=pop; stack: context.get_element(name) */
1.1 paf 415: };
416: name_advance2: name_expr_value {
417: /* stack: context */
418: $$=$1; /* stack: context,name */
1.54 paf 419: O($$, OP_GET_ELEMENT); /* name=pop; context=pop; stack: context.get_element(name) */
1.1 paf 420: }
1.4 paf 421: | STRING BOGUS
1.1 paf 422: ;
423: name_expr_value:
1.4 paf 424: STRING /* subname_is_const */
1.1 paf 425: | name_expr_subvar_value /* $subname_is_var_value */
1.160 parser 426: | name_expr_with_subvar_value /* xxx$part_of_subname_is_var_value */
1.166 parser 427: | name_square_code_value /* [codes] */
1.1 paf 428: ;
429: name_expr_subvar_value: '$' subvar_ref_name_rdive {
430: $$=$2;
1.54 paf 431: O($$, OP_GET_ELEMENT);
1.1 paf 432: };
1.4 paf 433: name_expr_with_subvar_value: STRING subvar_get_writes {
1.25 paf 434: $$=N(POOL);
1.54 paf 435: O($$, OP_CREATE_EWPOOL);
1.9 paf 436: P($$, $1);
1.102 paf 437: O($$, OP_WRITE_VALUE);
1.9 paf 438: P($$, $2);
1.54 paf 439: O($$, OP_REDUCE_EWPOOL);
1.1 paf 440: };
1.166 parser 441: name_square_code_value: '[' codes ']' {
1.160 parser 442: $$=N(POOL);
443: O($$, OP_CREATE_EWPOOL);
444: P($$, $2);
445: O($$, OP_REDUCE_EWPOOL);
446: };
1.154 parser 447: subvar_ref_name_rdive: STRING {
1.25 paf 448: $$=N(POOL);
1.54 paf 449: O($$, OP_WITH_READ);
1.9 paf 450: P($$, $1);
1.1 paf 451: };
1.9 paf 452: subvar_get_writes: subvar__get_write | subvar_get_writes subvar__get_write { $$=$1; P($$, $2) };
1.1 paf 453: subvar__get_write: '$' subvar_ref_name_rdive {
454: $$=$2;
1.54 paf 455: O($$, OP_GET_ELEMENT__WRITE);
1.42 paf 456: };
457:
1.154 parser 458: class_prefix:
459: class_static_prefix
460: | class_constructor_prefix
461: ;
1.155 parser 462: class_static_prefix: STRING ':' {
463: $$=$1; // stack: class name string
464: O($$, OP_GET_CLASS);
465: };
466: class_constructor_prefix: class_static_prefix ':' {
1.154 parser 467: $$=$1;
468: if(!PC.object_constructor_allowed) {
469: strcpy(PC.error, ":: not allowed here");
470: YYERROR;
471: }
1.155 parser 472: O($$, OP_PREPARE_TO_CONSTRUCT_OBJECT);
1.1 paf 473: };
474:
1.53 paf 475:
1.56 paf 476: /* expr */
1.53 paf 477:
1.81 paf 478: expr_value: expr {
479: if(($$=$1)->size()==2) // only one string literal in there?
1.62 paf 480: change_string_literal_to_double_literal($$); // make that string literal Double
481: };
1.56 paf 482: expr:
1.62 paf 483: STRING
1.64 paf 484: | get_value
1.66 paf 485: | call_value
1.64 paf 486: | '"' string_inside_quotes_value '"' { $$ = $2; }
1.145 parser 487: | '\'' string_inside_quotes_value '\'' { $$ = $2; }
1.60 paf 488: | '(' expr ')' { $$ = $2; }
489: /* stack: operand // stack: @operand */
490: | '-' expr %prec NEG { $$=$2; O($$, OP_NEG) }
1.166 parser 491: | '+' expr %prec NEG { $$=$2 }
1.68 paf 492: | '~' expr { $$=$2; O($$, OP_INV) }
493: | '!' expr { $$=$2; O($$, OP_NOT) }
494: | "def" expr { $$=$2; O($$, OP_DEF) }
495: | "in" expr { $$=$2; O($$, OP_IN) }
496: | "-f" expr { $$=$2; O($$, OP_FEXISTS) }
1.127 paf 497: | "-d" expr { $$=$2; O($$, OP_DEXISTS) }
1.60 paf 498: /* stack: a,b // stack: a@b */
499: | expr '-' expr { $$=$1; P($$, $3); O($$, OP_SUB) }
500: | expr '+' expr { $$=$1; P($$, $3); O($$, OP_ADD) }
501: | expr '*' expr { $$=$1; P($$, $3); O($$, OP_MUL) }
502: | expr '/' expr { $$=$1; P($$, $3); O($$, OP_DIV) }
503: | expr '%' expr { $$=$1; P($$, $3); O($$, OP_MOD) }
504: | expr '&' expr { $$=$1; P($$, $3); O($$, OP_BIN_AND) }
505: | expr '|' expr { $$=$1; P($$, $3); O($$, OP_BIN_OR) }
506: | expr '#' expr { $$=$1; P($$, $3); O($$, OP_BIN_XOR) }
507: | expr "&&" expr { $$=$1; P($$, $3); O($$, OP_LOG_AND) }
508: | expr "||" expr { $$=$1; P($$, $3); O($$, OP_LOG_OR) }
509: | expr "##" expr { $$=$1; P($$, $3); O($$, OP_LOG_XOR) }
510: | expr '<' expr { $$=$1; P($$, $3); O($$, OP_NUM_LT) }
511: | expr '>' expr { $$=$1; P($$, $3); O($$, OP_NUM_GT) }
512: | expr "<=" expr { $$=$1; P($$, $3); O($$, OP_NUM_LE) }
513: | expr ">=" expr { $$=$1; P($$, $3); O($$, OP_NUM_GE) }
514: | expr "==" expr { $$=$1; P($$, $3); O($$, OP_NUM_EQ) }
515: | expr "!=" expr { $$=$1; P($$, $3); O($$, OP_NUM_NE) }
1.61 paf 516: | expr "lt" expr { $$=$1; P($$, $3); O($$, OP_STR_LT) }
517: | expr "gt" expr { $$=$1; P($$, $3); O($$, OP_STR_GT) }
518: | expr "le" expr { $$=$1; P($$, $3); O($$, OP_STR_LE) }
519: | expr "ge" expr { $$=$1; P($$, $3); O($$, OP_STR_GE) }
520: | expr "eq" expr { $$=$1; P($$, $3); O($$, OP_STR_EQ) }
521: | expr "ne" expr { $$=$1; P($$, $3); O($$, OP_STR_NE) }
1.95 paf 522: | expr "is" expr { $$=$1; P($$, $3); O($$, OP_IS) }
1.56 paf 523: ;
1.55 paf 524:
1.65 paf 525: string_inside_quotes_value: maybe_codes {
1.64 paf 526: $$=N(POOL);
527: O($$, OP_CREATE_SWPOOL); /* stack: empty write context */
1.69 paf 528: P($$, $1); /* some code that writes to that context */
1.64 paf 529: O($$, OP_REDUCE_SWPOOL); /* context=pop; stack: context.get_string() */
1.53 paf 530: };
1.1 paf 531:
1.27 paf 532: /* basics */
1.1 paf 533:
1.81 paf 534: write_string: STRING {
1.102 paf 535: // optimized from OP_STRING+OP_WRITE_VALUE to OP_STRING__WRITE
1.84 paf 536: change_string_literal_to_write_string_literal($$=$1)
1.54 paf 537: };
538:
1.157 parser 539: void_value: /* empty */ { $$=VL(NEW VVoid(POOL)) };
1.25 paf 540: empty: /* empty */ { $$=N(POOL) };
1.1 paf 541:
542: %%
1.105 paf 543: #endif
1.1 paf 544:
545: /*
546: 000$111(2222)00
547: 000$111{3333}00
1.9 paf 548: $,^: push,=0
1.1 paf 549: 1:( { break=pop
550: 2:( ) pop
551: 3:{ } pop
552:
553: 000^111(2222)4444{33333}4000
1.9 paf 554: $,^: push,=0
1.1 paf 555: 1:( { break=pop
556: 2:( )=4
557: 3:{ }=4
558: 4:[^({]=pop
559: */
560:
1.110 paf 561: static int yylex(YYSTYPE *lvalp, void *pc) {
1.114 paf 562: #define lexical_brackets_nestage PC.brackets_nestages[PC.sp]
1.48 paf 563: #define RC {result=c; goto break2; }
1.1 paf 564:
565: register int c;
566: int result;
567:
1.114 paf 568: if(PC.pending_state) {
569: result=PC.pending_state;
570: PC.pending_state=0;
1.1 paf 571: return result;
572: }
573:
1.114 paf 574: const char *begin=PC.source;
1.91 paf 575: const char *end;
1.114 paf 576: int begin_line=PC.line;
1.67 paf 577: int skip_analized=0;
1.50 paf 578: while(true) {
1.114 paf 579: c=*(end=(PC.source++));
1.166 parser 580: // fprintf(stderr, "\nchar: %c %02X; nestage: %d, sp=%d", c, c, lexical_brackets_nestage, PC.sp);
1.1 paf 581:
1.4 paf 582: if(c=='\n') {
1.114 paf 583: PC.line++;
584: PC.col=0;
1.10 paf 585: } else
1.114 paf 586: PC.col++;
1.73 paf 587:
1.171 parser 588: if(c=='@' && PC.col==0+1) {
589: if(PC.ls==LS_USER) {
590: push_LS(PC, LS_DEF_NAME);
591: RC;
592: } else // @ in first column inside some code
593: result=BAD_METHOD_DECL_START;
594: goto break2;
595: } else if(c=='^')
1.169 parser 596: switch(PC.ls) {
597: case LS_EXPRESSION_VAR_NAME_WITH_COLON:
598: case LS_EXPRESSION_VAR_NAME_WITHOUT_COLON:
599: case LS_VAR_NAME_SIMPLE_WITH_COLON:
600: case LS_VAR_NAME_SIMPLE_WITHOUT_COLON:
601: case LS_VAR_NAME_CURLY:
602: case LS_METHOD_NAME:
603: case LS_COMMENT:
604: case LS_DEF_COMMENT:
605: // no literals in names, please
606: break;
607: default:
1.114 paf 608: switch(*PC.source) {
1.165 parser 609: // ^escaping some punctuators
1.48 paf 610: case '^': case '$': case ';':
1.126 paf 611: case '(': case ')':
1.48 paf 612: case '[': case ']':
613: case '{': case '}':
1.172 ! parser 614: case '"': case ':':
1.40 paf 615: if(end!=begin) {
616: // append piece till ^
1.121 paf 617: PC.string->APPEND_CLEAN(begin, end-begin, PC.file, begin_line);
1.40 paf 618: }
1.63 paf 619: // reset piece 'begin' position & line
1.164 parser 620: end=begin=PC.source; // ^
1.114 paf 621: begin_line=PC.line;
1.164 parser 622: if(PC.ls==LS_METHOD_AFTER) {
623: pop_LS(PC);
624: result=EON;
1.165 parser 625: skip_analized=-1; // return to ^ afterwards to assure it's literality
1.164 parser 626: goto break2;
627: } else {
628: // skip over _ after ^
629: PC.source++; PC.col++;
630: // skip analysis = forced literal
631: continue;
632: }
1.114 paf 633:
634: // converting ^#HH into char(hex(HH))
635: case '#':
636: if(end!=begin) {
637: // append piece till ^
1.121 paf 638: PC.string->APPEND_CLEAN(begin, end-begin, PC.file, begin_line);
1.114 paf 639: }
640: // #HH ?
641: if(PC.source[0]=='#' && PC.source[1] && PC.source[2]) {
642: char *hex=(char *)POOL.malloc(1);
643: hex[0]=
644: hex_value[(unsigned char)PC.source[1]]*0x10+
645: hex_value[(unsigned char)PC.source[2]];
646: if(hex[0]==0) {
647: result=BAD_HEX_LITERAL;
648: goto break2; // wrong hex value[no ^#00 chars allowed]: bail out
649: }
650: // append char(hex(HH))
1.121 paf 651: PC.string->APPEND_CLEAN(hex, 1, PC.file, begin_line);
1.114 paf 652: // skip over ^#HH
653: PC.source+=3;
654: PC.col+=3;
655: // reset piece 'begin' position & line
656: begin=PC.source; // ^
657: begin_line=PC.line;
658: continue;
659: }
660: break;
1.1 paf 661: }
1.169 parser 662: break;
663: }
1.113 paf 664: // #comment start skipping
1.114 paf 665: if(c=='#' && PC.col==1) {
1.112 paf 666: if(end!=begin) {
667: // append piece till #
1.121 paf 668: PC.string->APPEND_CLEAN(begin, end-begin, PC.file, begin_line);
1.112 paf 669: }
670: // fall into COMMENT lexical state [wait for \n]
671: push_LS(PC, LS_COMMENT);
672: }
1.114 paf 673: switch(PC.ls) {
1.10 paf 674:
675: // USER'S = NOT OURS
1.1 paf 676: case LS_USER:
1.166 parser 677: case LS_NAME_SQUARE_PART: // name.[here].xxx
1.153 parser 678: if(PC.trim_bof)
679: switch(c) {
680: case '\n': case ' ': case '\t':
1.152 parser 681: begin=PC.source;
682: begin_line=PC.line;
683: continue; // skip it
1.153 parser 684: default:
685: PC.trim_bof=false;
1.152 parser 686: }
1.48 paf 687: switch(c) {
688: case '$':
1.166 parser 689: push_LS(PC, LS_VAR_NAME_SIMPLE_WITH_COLON);
1.48 paf 690: RC;
691: case '^':
692: push_LS(PC, LS_METHOD_NAME);
693: RC;
1.166 parser 694: case ']':
695: if(PC.ls==LS_NAME_SQUARE_PART)
696: if(--lexical_brackets_nestage==0) {// $name.[co<]?>de<]?>
697: pop_LS(PC); // $name.[co<]>de<]!>
698: RC;
699: }
1.160 parser 700: break;
1.166 parser 701: case '[': // $name.[co<[>de]
702: if(PC.ls==LS_NAME_SQUARE_PART)
703: lexical_brackets_nestage++;
1.161 parser 704: break;
1.112 paf 705: }
706: break;
707:
708: // #COMMENT
709: case LS_COMMENT:
710: if(c=='\n') {
711: // skip comment
1.114 paf 712: begin=PC.source;
713: begin_line=PC.line;
1.112 paf 714:
715: pop_LS(PC);
716: continue;
1.1 paf 717: }
1.48 paf 718: break;
719:
720: // STRING IN EXPRESSION
1.145 parser 721: case LS_EXPRESSION_STRING_QUOTED:
722: case LS_EXPRESSION_STRING_APOSTROFED:
1.48 paf 723: switch(c) {
724: case '"':
1.145 parser 725: case '\'':
726: if(
727: PC.ls == LS_EXPRESSION_STRING_QUOTED && c=='"' ||
728: PC.ls == LS_EXPRESSION_STRING_APOSTROFED && c=='\'') {
729: pop_LS(PC); //"abc". | 'abc'.
730: RC;
731: }
732: break;
1.48 paf 733: case '$':
1.166 parser 734: push_LS(PC, LS_VAR_NAME_SIMPLE_WITH_COLON);
1.48 paf 735: RC;
736: case '^':
1.10 paf 737: push_LS(PC, LS_METHOD_NAME);
1.48 paf 738: RC;
1.10 paf 739: }
740: break;
741:
742: // METHOD DEFINITION
743: case LS_DEF_NAME:
1.48 paf 744: switch(c) {
745: case '[':
1.114 paf 746: PC.ls=LS_DEF_PARAMS;
1.48 paf 747: RC;
748: case '\n':
1.114 paf 749: PC.ls=LS_DEF_SPECIAL_BODY;
1.48 paf 750: RC;
1.10 paf 751: }
752: break;
1.48 paf 753:
1.10 paf 754: case LS_DEF_PARAMS:
1.48 paf 755: switch(c) {
756: case ';':
757: RC;
758: case ']':
1.114 paf 759: PC.ls=*PC.source=='['?LS_DEF_LOCALS:LS_DEF_COMMENT;
1.48 paf 760: RC;
1.49 paf 761: case '\n': // wrong. bailing out
1.10 paf 762: pop_LS(PC);
1.48 paf 763: RC;
1.10 paf 764: }
765: break;
1.48 paf 766:
1.10 paf 767: case LS_DEF_LOCALS:
1.48 paf 768: switch(c) {
769: case '[':
770: case ';':
771: RC;
772: case ']':
1.114 paf 773: PC.ls=LS_DEF_COMMENT;
1.48 paf 774: RC;
775: case '\n': // wrong. bailing out
1.10 paf 776: pop_LS(PC);
1.48 paf 777: RC;
1.10 paf 778: }
779: break;
1.48 paf 780:
1.10 paf 781: case LS_DEF_COMMENT:
782: if(c=='\n') {
783: pop_LS(PC);
1.48 paf 784: RC;
1.37 paf 785: }
786: break;
787:
1.48 paf 788: case LS_DEF_SPECIAL_BODY:
1.147 parser 789: // @todo in case
790: // ################
791: // @next-method
792: // we are here with c=='@'
793: // which is wrong, and need action
1.37 paf 794: if(c=='\n') {
1.114 paf 795: switch(*PC.source) {
1.48 paf 796: case '@': case 0: // end of special_code
1.37 paf 797: pop_LS(PC);
1.48 paf 798: break;
799: }
800: RC;
801: }
802: break;
803:
804: // (EXPRESSION)
1.69 paf 805: case LS_VAR_ROUND:
806: case LS_METHOD_ROUND:
1.48 paf 807: switch(c) {
808: case ')':
809: if(--lexical_brackets_nestage==0)
1.114 paf 810: if(PC.ls==LS_METHOD_ROUND) // method round param ended
811: PC.ls=LS_METHOD_AFTER; // look for method end
812: else // PC.ls==LS_VAR_ROUND // variable constructor ended
1.69 paf 813: pop_LS(PC); // return to normal life
1.48 paf 814: RC;
815: case '$':
1.166 parser 816: push_LS(PC, LS_EXPRESSION_VAR_NAME_WITH_COLON);
1.48 paf 817: RC;
818: case '^':
819: push_LS(PC, LS_METHOD_NAME);
820: RC;
821: case '(':
822: lexical_brackets_nestage++;
823: RC;
1.67 paf 824: case '-':
1.127 paf 825: switch(*PC.source) {
826: case 'f': // -f
1.67 paf 827: skip_analized=1;
828: result=FEXISTS;
1.127 paf 829: goto break2;
830: case 'd': // -d
831: skip_analized=1;
832: result=DEXISTS;
833: goto break2;
834: default:
1.67 paf 835: result=c;
1.127 paf 836: goto break2;
837: }
1.67 paf 838: goto break2;
839: case '+': case '*': case '/': case '%':
1.58 paf 840: case '~':
1.48 paf 841: case ';':
842: RC;
1.59 paf 843: case '&': case '|': case '#':
1.114 paf 844: if(*PC.source==c) { // && ||
1.59 paf 845: result=c=='#'?LXOR:c=='&'?LAND:LOR;
1.67 paf 846: skip_analized=1;
1.58 paf 847: } else
848: result=c;
849: goto break2;
850: case '<': case '>': case '=': case '!':
1.114 paf 851: if(*PC.source=='=') { // <= >= == !=
1.67 paf 852: skip_analized=1;
1.58 paf 853: switch(c) {
854: case '<': result=NLE; break;
855: case '>': result=NGE; break;
856: case '=': result=NEQ; break;
857: case '!': result=NNE; break;
858: }
859: } else
860: result=c;
861: goto break2;
1.48 paf 862: case '"':
1.145 parser 863: push_LS(PC, LS_EXPRESSION_STRING_QUOTED);
864: RC;
865: case '\'':
866: push_LS(PC, LS_EXPRESSION_STRING_APOSTROFED);
1.48 paf 867: RC;
1.50 paf 868: case 'l': case 'g': case 'e': case 'n':
1.51 paf 869: if(end==begin) // right after whitespace
1.117 paf 870: if(isspace(PC.source[1])) {
871: switch(*PC.source) {
872: // case '?': // ok [and bad cases, yacc would bark at them]
873: case 't': // lt gt [et nt]
874: result=c=='l'?SLT:c=='g'?SGT:BAD_STRING_COMPARISON_OPERATOR;
875: skip_analized=1;
876: goto break2;
877: case 'e': // le ge ne [ee]
878: result=c=='l'?SLE:c=='g'?SGE:c=='n'?SNE:BAD_STRING_COMPARISON_OPERATOR;
879: skip_analized=1;
880: goto break2;
881: case 'q': // eq [lq gq nq]
882: result=c=='e'?SEQ:BAD_STRING_COMPARISON_OPERATOR;
883: skip_analized=1;
884: goto break2;
885: }
1.67 paf 886: }
887: break;
888: case 'i':
889: if(end==begin) // right after whitespace
1.117 paf 890: if(isspace(PC.source[1])) {
891: switch(PC.source[0]) {
892: case 'n': // in
1.95 paf 893: skip_analized=1;
894: result=IN;
895: goto break2;
1.117 paf 896: case 's': // is
1.95 paf 897: skip_analized=1;
898: result=IS;
899: goto break2;
900: }
1.67 paf 901: }
902: break;
903: case 'd':
904: if(end==begin) // right after whitespace
1.114 paf 905: if(PC.source[0]=='e' && PC.source[1]=='f') { // def
1.67 paf 906: skip_analized=2;
907: result=DEF;
1.58 paf 908: goto break2;
1.50 paf 909: }
1.48 paf 910: break;
911: case ' ': case '\t': case '\n':
1.63 paf 912: if(end!=begin) { // there were a string after previous operator?
913: result=0; // return that string
914: goto break2;
1.48 paf 915: }
1.63 paf 916: // that's a leading|traling space or after-operator-space
917: // ignoring it
918: // reset piece 'begin' position & line
1.114 paf 919: begin=PC.source; // after whitespace char
920: begin_line=PC.line;
1.48 paf 921: continue;
1.1 paf 922: }
923: break;
924:
1.10 paf 925: // VARIABLE GET/PUT/WITH
1.166 parser 926: case LS_VAR_NAME_SIMPLE_WITH_COLON:
927: case LS_VAR_NAME_SIMPLE_WITHOUT_COLON:
928: case LS_EXPRESSION_VAR_NAME_WITH_COLON:
929: case LS_EXPRESSION_VAR_NAME_WITHOUT_COLON:
930: if(
931: PC.ls==LS_EXPRESSION_VAR_NAME_WITH_COLON ||
932: PC.ls==LS_EXPRESSION_VAR_NAME_WITHOUT_COLON) {
1.56 paf 933: // name in expr ends also before binary operators
1.48 paf 934: switch(c) {
1.92 paf 935: case '-':
1.48 paf 936: pop_LS(PC);
1.114 paf 937: PC.source--; if(--PC.col<0) { PC.line--; PC.col=-1; }
1.48 paf 938: result=EON;
939: goto break2;
940: }
941: }
1.166 parser 942: if(
943: PC.ls==LS_VAR_NAME_SIMPLE_WITHOUT_COLON ||
944: PC.ls==LS_EXPRESSION_VAR_NAME_WITHOUT_COLON) {
1.142 parser 945: // name already has ':', stop before next
946: switch(c) {
947: case ':':
948: pop_LS(PC);
949: PC.source--; if(--PC.col<0) { PC.line--; PC.col=-1; }
950: result=EON;
951: goto break2;
952: }
953: }
1.48 paf 954: switch(c) {
955: case 0:
956: case ' ': case '\t': case '\n':
957: case ';':
1.126 paf 958: case ']': case '}': case ')':
959: case '"': case '\'':
1.139 parser 960: case '<': case '>': // these stand for HTML brackets AND expression binary ops
1.92 paf 961: case '+': case '*': case '/': case '%':
962: case '&': case '|':
963: case '=': case '!':
1.99 paf 964: // common delimiters
1.158 parser 965: case ',': case '?':
1.139 parser 966: // before call
967: case '^':
1.1 paf 968: pop_LS(PC);
1.114 paf 969: PC.source--; if(--PC.col<0) { PC.line--; PC.col=-1; }
1.13 paf 970: result=EON;
1.1 paf 971: goto break2;
1.48 paf 972: case '[':
1.162 parser 973: // $name.<[>code]
974: if(PC.col>1/*not first column*/ && (
1.163 parser 975: end[-1]=='$'/*was start of get*/ ||
976: end[-1]==':'/*was class name delim */ ||
977: end[-1]=='.'/*was name delim */
1.162 parser 978: )) {
1.166 parser 979: push_LS(PC, LS_NAME_SQUARE_PART);
1.162 parser 980: lexical_brackets_nestage=1;
981: RC;
982: }
1.114 paf 983: PC.ls=LS_VAR_SQUARE;
1.1 paf 984: lexical_brackets_nestage=1;
1.48 paf 985: RC;
986: case '{':
987: if(begin==end) { // ${name}, no need of EON, switching LS
1.114 paf 988: PC.ls=LS_VAR_NAME_CURLY;
1.48 paf 989: } else {
1.114 paf 990: PC.ls=LS_VAR_CURLY;
1.48 paf 991: lexical_brackets_nestage=1;
992: }
1.69 paf 993:
1.48 paf 994: RC;
995: case '(':
1.114 paf 996: PC.ls=LS_VAR_ROUND;
1.1 paf 997: lexical_brackets_nestage=1;
1.48 paf 998: RC;
999: case '.': // name part delim
1000: case '$': // name part subvar
1.160 parser 1001: case ':': // class<:>name
1.166 parser 1002: // go to _WITHOUT_COLON state variant...
1003: if(PC.ls==LS_VAR_NAME_SIMPLE_WITH_COLON)
1004: PC.ls=LS_VAR_NAME_SIMPLE_WITHOUT_COLON;
1005: else if(PC.ls==LS_EXPRESSION_VAR_NAME_WITH_COLON)
1006: PC.ls=LS_EXPRESSION_VAR_NAME_WITHOUT_COLON;
1007: // ...stop before next ':'
1.48 paf 1008: RC;
1.1 paf 1009: }
1010: break;
1.48 paf 1011:
1.1 paf 1012: case LS_VAR_NAME_CURLY:
1.48 paf 1013: switch(c) {
1.162 parser 1014: case '[':
1.166 parser 1015: // ${name.<[>code]}
1016: push_LS(PC, LS_NAME_SQUARE_PART);
1.160 parser 1017: lexical_brackets_nestage=1;
1018: RC;
1.48 paf 1019: case '}': // ${name} finished, restoring LS
1.1 paf 1020: pop_LS(PC);
1.48 paf 1021: RC;
1022: case '.': // name part delim
1023: case '$': // name part subvar
1024: case ':': // ':name' or 'class:name'
1025: RC;
1.1 paf 1026: }
1027: break;
1.48 paf 1028:
1029: case LS_VAR_SQUARE:
1030: switch(c) {
1031: case '$':
1.166 parser 1032: push_LS(PC, LS_VAR_NAME_SIMPLE_WITH_COLON);
1.48 paf 1033: RC;
1034: case '^':
1.10 paf 1035: push_LS(PC, LS_METHOD_NAME);
1.48 paf 1036: RC;
1037: case ']':
1.1 paf 1038: if(--lexical_brackets_nestage==0) {
1039: pop_LS(PC);
1.48 paf 1040: RC;
1.1 paf 1041: }
1.48 paf 1042: break;
1043: case ';': // operator_or_fmt;value delim
1044: RC;
1045: case '[':
1046: lexical_brackets_nestage++;
1047: break;
1.1 paf 1048: }
1049: break;
1.48 paf 1050:
1.1 paf 1051: case LS_VAR_CURLY:
1.48 paf 1052: switch(c) {
1053: case '$':
1.166 parser 1054: push_LS(PC, LS_VAR_NAME_SIMPLE_WITH_COLON);
1.48 paf 1055: RC;
1056: case '^':
1.10 paf 1057: push_LS(PC, LS_METHOD_NAME);
1.48 paf 1058: RC;
1059: case '}':
1.1 paf 1060: if(--lexical_brackets_nestage==0) {
1061: pop_LS(PC);
1.48 paf 1062: RC;
1.1 paf 1063: }
1.48 paf 1064: break;
1065: case '{':
1.1 paf 1066: lexical_brackets_nestage++;
1.48 paf 1067: break;
1068: }
1.1 paf 1069: break;
1070:
1.10 paf 1071: // METHOD CALL
1.1 paf 1072: case LS_METHOD_NAME:
1.48 paf 1073: switch(c) {
1074: case '[':
1.166 parser 1075: // ^name.<[>code].xxx
1.162 parser 1076: if(PC.col>1/*not first column*/ && (
1.163 parser 1077: end[-1]=='^'/*was start of call*/ || // never, ^[ is literal...
1078: end[-1]==':'/*was class name delim */ ||
1079: end[-1]=='.'/*was name delim */
1.162 parser 1080: )) {
1.166 parser 1081: push_LS(PC, LS_NAME_SQUARE_PART);
1.162 parser 1082: lexical_brackets_nestage=1;
1083: RC;
1084: }
1.114 paf 1085: PC.ls=LS_METHOD_SQUARE;
1.1 paf 1086: lexical_brackets_nestage=1;
1.48 paf 1087: RC;
1088: case '{':
1.114 paf 1089: PC.ls=LS_METHOD_CURLY;
1.1 paf 1090: lexical_brackets_nestage=1;
1.48 paf 1091: RC;
1.69 paf 1092: case '(':
1.114 paf 1093: PC.ls=LS_METHOD_ROUND;
1.69 paf 1094: lexical_brackets_nestage=1;
1095: RC;
1.48 paf 1096: case '.': // name part delim
1097: case '$': // name part subvar
1098: case ':': // ':name' or 'class:name'
1.170 parser 1099: case '^': // ^abc^xxx wrong. bailing out
1100: case ']': case '}': case ')': // ^abc]}) wrong. bailing out
1.48 paf 1101: RC;
1.1 paf 1102: }
1103: break;
1.48 paf 1104:
1105: case LS_METHOD_SQUARE:
1106: switch(c) {
1107: case '$':
1.166 parser 1108: push_LS(PC, LS_VAR_NAME_SIMPLE_WITH_COLON);
1.48 paf 1109: RC;
1110: case '^':
1.10 paf 1111: push_LS(PC, LS_METHOD_NAME);
1.48 paf 1112: RC;
1113: case ';': // param delim
1114: RC;
1115: case ']':
1.1 paf 1116: if(--lexical_brackets_nestage==0) {
1.114 paf 1117: PC.ls=LS_METHOD_AFTER;
1.48 paf 1118: RC;
1.1 paf 1119: }
1.48 paf 1120: break;
1121: case '[':
1.1 paf 1122: lexical_brackets_nestage++;
1.48 paf 1123: break;
1124: }
1.1 paf 1125: break;
1.48 paf 1126:
1.1 paf 1127: case LS_METHOD_CURLY:
1.48 paf 1128: switch(c) {
1129: case '$':
1.166 parser 1130: push_LS(PC, LS_VAR_NAME_SIMPLE_WITH_COLON);
1.48 paf 1131: RC;
1132: case '^':
1.10 paf 1133: push_LS(PC, LS_METHOD_NAME);
1.94 paf 1134: RC;
1135: case ';': // param delim
1.48 paf 1136: RC;
1137: case '}':
1.1 paf 1138: if(--lexical_brackets_nestage==0) {
1.114 paf 1139: PC.ls=LS_METHOD_AFTER;
1.48 paf 1140: RC;
1.1 paf 1141: }
1.48 paf 1142: break;
1143: case '{':
1.1 paf 1144: lexical_brackets_nestage++;
1.48 paf 1145: break;
1146: }
1.1 paf 1147: break;
1.48 paf 1148:
1.1 paf 1149: case LS_METHOD_AFTER:
1.69 paf 1150: if(c=='[') {/* ][ }[ )[ */
1.114 paf 1151: PC.ls=LS_METHOD_SQUARE;
1.1 paf 1152: lexical_brackets_nestage=1;
1.48 paf 1153: RC;
1.1 paf 1154: }
1.69 paf 1155: if(c=='{') {/* ]{ }{ ){ */
1.114 paf 1156: PC.ls=LS_METHOD_CURLY;
1.69 paf 1157: lexical_brackets_nestage=1;
1158: RC;
1159: }
1160: if(c=='(') {/* ]( }( )( */
1.114 paf 1161: PC.ls=LS_METHOD_ROUND;
1.1 paf 1162: lexical_brackets_nestage=1;
1.48 paf 1163: RC;
1.1 paf 1164: }
1165: pop_LS(PC);
1.114 paf 1166: PC.source--; if(--PC.col<0) { PC.line--; PC.col=-1; }
1.13 paf 1167: result=EON;
1.1 paf 1168: goto break2;
1169: }
1.9 paf 1170: if(c==0) {
1.1 paf 1171: result=-1;
1172: break;
1173: }
1174: }
1175:
1176: break2:
1.59 paf 1177: if(end!=begin) { // there is last piece?
1178: if((c=='@' || c==0) && end[-1]=='\n') { // we are before LS_DEF_NAME or EOF?
1179: // strip last \n
1.10 paf 1180: end--;
1.137 parser 1181: if(end!=begin && end[-1]=='\n') // allow one empty line before LS_DEF_NAME
1182: end--;
1.59 paf 1183: }
1.133 parser 1184: if(end!=begin && PC.ls!=LS_COMMENT) { // last piece still alive and not comment?
1.59 paf 1185: // append it
1.121 paf 1186: PC.string->APPEND_CLEAN(begin, end-begin, PC.file, begin_line/*, start_col*/);
1.30 paf 1187: }
1.59 paf 1188: }
1.114 paf 1189: if(PC.string->size()) { // something accumulated?
1.17 paf 1190: // create STRING value: array of OP_VALUE+vstring
1.114 paf 1191: *lvalp=VL(NEW VString(*PC.string));
1.10 paf 1192: // new pieces storage
1.114 paf 1193: PC.string=NEW String(POOL);
1.58 paf 1194: // make current result be pending for next call, return STRING for now
1.114 paf 1195: PC.pending_state=result; result=STRING;
1.58 paf 1196: }
1.67 paf 1197: if(skip_analized) {
1.114 paf 1198: PC.source+=skip_analized; PC.col+=skip_analized;
1.1 paf 1199: }
1.58 paf 1200: return result;
1.1 paf 1201: }
1202:
1.110 paf 1203: static int real_yyerror(parse_control *pc, char *s) { // Called by yyparse on error
1.114 paf 1204: strncpy(PC.error, s, MAX_STRING);
1.1 paf 1205: return 1;
1.110 paf 1206: }
1.1 paf 1207:
1.110 paf 1208: static void yyprint(FILE *file, int type, YYSTYPE value) {
1209: if(type==STRING)
1.120 paf 1210: fprintf(file, " \"%s\"", LA2S(value)->cstr());
1.110 paf 1211: }
E-mail: