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