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