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