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