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