Annotation of parser3/src/main/compile.y, revision 1.251
1.168 parser 1: %{
1.105 paf 2: /** @file
1.106 paf 3: Parser: compiler(lexical parser and grammar).
4:
1.239 misha 5: Copyright (c) 2001-2009 ArtLebedev Group (http://www.artlebedev.com)
1.168 parser 6: Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
1.217 paf 7:
1.251 ! misha 8: $Id: compile.y,v 1.250 2009-08-01 04:58:45 misha 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.206 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.206 paf 27: #define yyerror(msg) real_yyerror((Parse_control *)pc, msg)
1.9 paf 28: #define YYPRINT(file, type, value) yyprint(file, type, value)
1.1 paf 29:
1.206 paf 30: // includes
31:
1.1 paf 32: #include "compile_tools.h"
1.8 paf 33: #include "pa_value.h"
1.12 paf 34: #include "pa_request.h"
1.39 paf 35: #include "pa_vobject.h"
1.52 paf 36: #include "pa_vdouble.h"
1.98 paf 37: #include "pa_globals.h"
1.141 parser 38: #include "pa_vvoid.h"
1.200 paf 39: #include "pa_vmethod_frame.h"
1.39 paf 40:
1.206 paf 41: // defines
42:
1.97 paf 43: #define USE_CONTROL_METHOD_NAME "USE"
1.226 misha 44: #define OPTIONS_CONTROL_METHOD_NAME "OPTIONS"
45: #define OPTION_ALL_VARS_LOCAL_NAME "locals"
1.230 misha 46: #define OPTION_PARTIAL_CLASS "partial"
1.238 misha 47: #define REM_OPERATOR_NAME "rem"
1.1 paf 48:
1.206 paf 49: // forwards
50:
51: static int real_yyerror(Parse_control* pc, char* s);
52: static void yyprint(FILE* file, int type, YYSTYPE value);
53: static int yylex(YYSTYPE* lvalp, void* pc);
1.1 paf 54:
1.216 paf 55: static const VBool vfalse(false);
56: static const VBool vtrue(true);
57: static const VVoid vvoid;
58:
1.8 paf 59: // local convinient inplace typecast & var
1.205 paf 60: #undef PC
1.206 paf 61: #define PC (*(Parse_control *)pc)
62: #undef POOL
1.114 paf 63: #define POOL (*PC.pool)
1.107 paf 64: #ifndef DOXYGEN
1.1 paf 65: %}
66:
67: %pure_parser
68:
1.13 paf 69: %token EON
1.4 paf 70: %token STRING
1.1 paf 71: %token BOGUS
1.55 paf 72:
1.58 paf 73: %token BAD_STRING_COMPARISON_OPERATOR
1.114 paf 74: %token BAD_HEX_LITERAL
1.171 parser 75: %token BAD_METHOD_DECL_START
1.193 paf 76: %token BAD_METHOD_PARAMETER_NAME_CHARACTER
1.209 paf 77: %token BAD_NONWHITESPACE_CHARACTER_IN_EXPLICIT_RESULT_MODE
1.58 paf 78:
1.59 paf 79: %token LAND "&&"
1.58 paf 80: %token LOR "||"
1.193 paf 81: %token LXOR "!||"
82: %token NXOR "!|"
1.58 paf 83:
84: %token NLE "<="
85: %token NGE ">="
86: %token NEQ "=="
87: %token NNE "!="
1.195 paf 88: %token NSL "<<"
89: %token NSR ">>"
1.58 paf 90:
91: %token SLT "lt"
92: %token SGT "gt"
93: %token SLE "le"
94: %token SGE "ge"
95: %token SEQ "eq"
96: %token SNE "ne"
97:
1.67 paf 98: %token DEF "def"
99: %token IN "in"
100: %token FEXISTS "-f"
1.127 paf 101: %token DEXISTS "-d"
1.95 paf 102: %token IS "is"
1.67 paf 103:
1.216 paf 104: %token LITERAL_TRUE "true"
105: %token LITERAL_FALSE "false"
106:
1.57 paf 107: /* logical */
1.193 paf 108: %left "!||"
1.57 paf 109: %left "||"
110: %left "&&"
1.131 paf 111: %left '<' '>' "<=" ">=" "lt" "gt" "le" "ge"
112: %left "==" "!=" "eq" "ne"
113: %left "is" "def" "in" "-f" "-d"
1.57 paf 114:
115: /* bitwise */
1.193 paf 116: %left "!|"
1.131 paf 117: %left '|'
118: %left '&'
1.202 paf 119: %left "<<" ">>"
1.57 paf 120:
1.56 paf 121: /* numerical */
1.202 paf 122: %left '+' '-'
123: %left '*' '/' '\\' '%'
124: %left NUNARY /* unary - + */
125:
126: /* out-of-group */
127: %left '~' /* bitwise */
128: %left '!' /* logical */
1.1 paf 129:
130: %%
1.195 paf 131: all:
1.10 paf 132: one_big_piece {
1.251 ! misha 133: Method* method=new Method(Method::CT_ANY,
1.81 paf 134: 0, 0, /*min, max numbered_params_count*/
1.75 paf 135: 0/*param_names*/, 0/*local_names*/,
136: $1/*parser_code*/, 0/*native_code*/);
1.251 ! misha 137: PC.cclass->set_method(PC.alias_method(main_method_name), method);
1.10 paf 138: }
139: | methods;
140:
141: methods: method | methods method;
142: one_big_piece: maybe_codes;
143:
1.34 paf 144: method: control_method | code_method;
145:
146: control_method: '@' STRING '\n'
1.132 paf 147: maybe_control_strings {
1.206 paf 148: const String& command=*LA2S(*$2);
1.34 paf 149: YYSTYPE strings_code=$4;
1.206 paf 150: if(strings_code->count()<1*OPERATIONS_PER_OPVALUE) {
1.114 paf 151: strcpy(PC.error, "@");
152: strcat(PC.error, command.cstr());
153: strcat(PC.error, " is empty");
1.37 paf 154: YYERROR;
155: }
1.74 paf 156: if(command==CLASS_NAME) {
1.206 paf 157: if(strings_code->count()==1*OPERATIONS_PER_OPVALUE) {
1.73 paf 158: // new class' name
1.206 paf 159: const String& name=*LA2S(*strings_code);
1.73 paf 160: // creating the class
1.206 paf 161: VStateless_class* cclass=new VClass;
1.226 misha 162: PC.cclass_new=cclass;
163: PC.cclass_new->set_name(name);
1.73 paf 164: } else {
1.206 paf 165: strcpy(PC.error, "@"CLASS_NAME" must contain only one line with class name (contains more then one)");
1.34 paf 166: YYERROR;
167: }
1.130 paf 168: } else if(command==USE_CONTROL_METHOD_NAME) {
1.206 paf 169: for(size_t i=0; i<strings_code->count(); i+=OPERATIONS_PER_OPVALUE)
170: PC.request.use_file(PC.request.main_class, *LA2S(*strings_code, i));
1.130 paf 171: } else if(command==BASE_NAME) {
1.226 misha 172: if(PC.append){
173: strcpy(PC.error, "can't set base while appending methods to class '");
174: strncat(PC.error, PC.cclass->name().cstr(), MAX_STRING/2);
175: strcat(PC.error, "'");
176: YYERROR;
177: }
178: PC.class_add();
1.188 paf 179: if(PC.cclass->base_class()) { // already changed from default?
1.130 paf 180: strcpy(PC.error, "class already have a base '");
1.226 misha 181: strncat(PC.error, PC.cclass->base_class()->name().cstr(), MAX_STRING/2);
1.130 paf 182: strcat(PC.error, "'");
183: YYERROR;
184: }
1.206 paf 185: if(strings_code->count()==1*OPERATIONS_PER_OPVALUE) {
186: const String& base_name=*LA2S(*strings_code);
187: if(Value* base_class_value=PC.request.classes().get(base_name)) {
188: // @CLASS == @BASE sanity check
189: if(VStateless_class *base_class=base_class_value->get_class()) {
190: if(PC.cclass==base_class) {
191: strcpy(PC.error, "@"CLASS_NAME" equals @"BASE_NAME);
192: YYERROR;
193: }
194: PC.cclass->get_class()->set_base(base_class);
195: } else { // they asked to derive from a class without methods ['env' & co]
196: strcpy(PC.error, base_name.cstr());
197: strcat(PC.error, ": you can not derive from this class in @"BASE_NAME);
198: YYERROR;
199: }
200: } else {
1.130 paf 201: strcpy(PC.error, base_name.cstr());
202: strcat(PC.error, ": undefined class in @"BASE_NAME);
1.73 paf 203: YYERROR;
204: }
1.34 paf 205: } else {
1.130 paf 206: strcpy(PC.error, "@"BASE_NAME" must contain sole name");
1.34 paf 207: YYERROR;
208: }
1.223 misha 209: } else if(command==OPTIONS_CONTROL_METHOD_NAME) {
210: for(size_t i=0; i<strings_code->count(); i+=OPERATIONS_PER_OPVALUE) {
211: const String& option=*LA2S(*strings_code, i);
1.226 misha 212: if(option==OPTION_ALL_VARS_LOCAL_NAME){
213: PC.set_all_vars_local();
1.230 misha 214: } else if(option==OPTION_PARTIAL_CLASS){
215: if(PC.cclass_new){
216: if(VStateless_class* existed=PC.get_existed_class(PC.cclass_new)){
217: if(!PC.reuse_existed_class(existed)){
218: strcpy(PC.error, "can't append methods to '");
219: strncat(PC.error, PC.cclass_new->name().cstr(), MAX_STRING/2);
220: strcat(PC.error, "' - the class wasn't marked as partial");
221: YYERROR;
222: }
1.226 misha 223: } else {
1.230 misha 224: // mark new class as partial. we can add methods to it later.
225: PC.cclass_new->set_partial();
1.226 misha 226: }
1.230 misha 227: } else {
228: strcpy(PC.error, "'"OPTION_PARTIAL_CLASS"' option should be used straight after @"CLASS_NAME);
1.226 misha 229: YYERROR;
230: }
1.223 misha 231: } else {
1.226 misha 232: strcpy(PC.error, "'");
233: strncat(PC.error, option.cstr(), MAX_STRING/2);
234: strcat(PC.error, "' invalid option. valid options are "
1.230 misha 235: "'"OPTION_PARTIAL_CLASS"' and '"OPTION_ALL_VARS_LOCAL_NAME"'");
1.223 misha 236: YYERROR;
237: }
238: }
1.130 paf 239: } else {
240: strcpy(PC.error, "'");
241: strncat(PC.error, command.cstr(), MAX_STRING/2);
242: strcat(PC.error, "' invalid special name. valid names are "
1.223 misha 243: "'"CLASS_NAME"', '"USE_CONTROL_METHOD_NAME"', '"BASE_NAME"' and '"OPTIONS_CONTROL_METHOD_NAME"'.");
1.130 paf 244: YYERROR;
1.34 paf 245: }
246: };
1.132 paf 247: maybe_control_strings: empty | control_strings;
1.206 paf 248: control_strings: control_string | control_strings control_string { $$=$1; P(*$$, *$2) };
1.37 paf 249: control_string: maybe_string '\n';
250: maybe_string: empty | STRING;
1.34 paf 251:
1.222 misha 252: code_method: '@' STRING bracketed_maybe_strings maybe_bracketed_strings maybe_comment '\n' {
1.226 misha 253: PC.class_add();
1.208 paf 254: PC.explicit_result=false;
1.10 paf 255:
256: YYSTYPE params_names_code=$3;
1.206 paf 257: ArrayString* params_names=0;
258: if(int size=params_names_code->count()) {
259: params_names=new ArrayString;
260: for(int i=0; i<size; i+=OPERATIONS_PER_OPVALUE)
261: *params_names+=LA2S(*params_names_code, i);
1.75 paf 262: }
1.10 paf 263:
264: YYSTYPE locals_names_code=$4;
1.206 paf 265: ArrayString* locals_names=0;
1.223 misha 266: bool all_vars_local=false;
1.206 paf 267: if(int size=locals_names_code->count()) {
268: locals_names=new ArrayString;
1.208 paf 269: for(int i=0; i<size; i+=OPERATIONS_PER_OPVALUE) {
270: const String* local_name=LA2S(*locals_names_code, i);
271: if(*local_name==RESULT_VAR_NAME)
272: PC.explicit_result=true;
1.226 misha 273: else if(*local_name==OPTION_ALL_VARS_LOCAL_NAME)
1.223 misha 274: all_vars_local=true;
1.208 paf 275: else
276: *locals_names+=local_name;
277: }
1.75 paf 278: }
1.231 misha 279: if(!all_vars_local && PC.cclass && PC.cclass->is_vars_local())
1.223 misha 280: all_vars_local=true;
1.10 paf 281:
1.208 paf 282: Method* method=new Method(
1.206 paf 283: //name,
1.122 paf 284: Method::CT_ANY,
1.81 paf 285: 0, 0/*min,max numbered_params_count*/,
1.76 paf 286: params_names, locals_names,
1.223 misha 287: 0/*to be filled later in next {} */, 0, all_vars_local);
1.221 misha 288:
1.208 paf 289: *reinterpret_cast<Method**>(&$$)=method;
290:
291: // todo: check [][;result;]
1.222 misha 292: } maybe_codes {
1.251 ! misha 293: Method* method=reinterpret_cast<Method*>($7);
1.231 misha 294: // fill in the code
1.251 ! misha 295: method->parser_code=$8;
1.231 misha 296:
297: // register in class
298: const String& name=*LA2S(*$2);
1.251 ! misha 299: PC.cclass->set_method(PC.alias_method(name), method);
1.8 paf 300: };
1.10 paf 301:
302: maybe_bracketed_strings: empty | bracketed_maybe_strings;
303: bracketed_maybe_strings: '[' maybe_strings ']' {$$=$2};
304: maybe_strings: empty | strings;
1.206 paf 305: strings: STRING | strings ';' STRING { $$=$1; P(*$$, *$3) };
1.10 paf 306:
307: maybe_comment: empty | STRING;
1.1 paf 308:
309: /* codes */
310:
1.10 paf 311: maybe_codes: empty | codes;
312:
1.206 paf 313: codes: code | codes code { $$=$1; P(*$$, *$2) };
1.81 paf 314: code: write_string | action;
1.209 paf 315: action: get | put | call;
1.1 paf 316:
317: /* get */
318:
1.64 paf 319: get: get_value {
1.238 misha 320: $$=N();
321: YYSTYPE code=$1;
1.247 misha 322: size_t count=code->count();
1.245 misha 323:
1.235 misha 324: #ifdef OPTIMIZE_BYTECODE_GET_ELEMENT
1.247 misha 325: if(
326: count!=3
327: || !maybe_change_first_opcode(*code, OP::OP_VALUE__GET_ELEMENT, /*=>*/OP::OP_VALUE__GET_ELEMENT__WRITE)
328: )
1.238 misha 329: #endif
1.247 misha 330:
1.245 misha 331: #ifdef OPTIMIZE_BYTECODE_GET_SELF_ELEMENT
1.247 misha 332: if(
333: count!=3
334: || !maybe_change_first_opcode(*code, OP::OP_WITH_SELF__VALUE__GET_ELEMENT, /*=>*/OP::OP_WITH_SELF__VALUE__GET_ELEMENT__WRITE)
335: )
1.245 misha 336: #endif
337:
1.239 misha 338: #ifdef OPTIMIZE_BYTECODE_GET_OBJECT_ELEMENT
1.247 misha 339: if(
340: count!=5
341: || !maybe_change_first_opcode(*code, OP::OP_GET_OBJECT_ELEMENT, /*=>*/OP::OP_GET_OBJECT_ELEMENT__WRITE)
342: )
1.239 misha 343: #endif
344:
345: #ifdef OPTIMIZE_BYTECODE_GET_OBJECT_VAR_ELEMENT
1.247 misha 346: if(
347: count!=5
348: || !maybe_change_first_opcode(*code, OP::OP_GET_OBJECT_VAR_ELEMENT, /*=>*/OP::OP_GET_OBJECT_VAR_ELEMENT__WRITE)
349: )
1.238 misha 350: #endif
1.247 misha 351: {
352: changetail_or_append(*code,
353: OP::OP_GET_ELEMENT, false, /*=>*/OP::OP_GET_ELEMENT__WRITE,
354: /*or */OP::OP_WRITE_VALUE
355: ); /* value=pop; wcontext.write(value) */
1.246 misha 356: }
1.247 misha 357:
1.238 misha 358: P(*$$, *code);
1.1 paf 359: };
1.163 parser 360: get_value: '$' get_name_value { $$=$2 };
1.64 paf 361: get_name_value: name_without_curly_rdive EON | name_in_curly_rdive;
1.1 paf 362: name_in_curly_rdive: '{' name_without_curly_rdive '}' { $$=$2 };
1.44 paf 363: name_without_curly_rdive:
364: name_without_curly_rdive_read
365: | name_without_curly_rdive_class;
1.19 paf 366: name_without_curly_rdive_read: name_without_curly_rdive_code {
1.206 paf 367: $$=N();
1.238 misha 368: YYSTYPE diving_code=$1;
1.239 misha 369: size_t count=diving_code->count();
1.247 misha 370:
371: if(maybe_make_self(*$$, *diving_code, count)) {
372: // $self.
373: } else
1.239 misha 374:
375: #ifdef OPTIMIZE_BYTECODE_GET_OBJECT_ELEMENT
1.247 misha 376: if(maybe_make_get_object_element(*$$, *diving_code, count)){
1.245 misha 377: // optimization for $object.field + ^object.method[
1.247 misha 378: } else
1.238 misha 379: #endif
1.239 misha 380:
381: #ifdef OPTIMIZE_BYTECODE_GET_OBJECT_VAR_ELEMENT
1.247 misha 382: if(maybe_make_get_object_var_element(*$$, *diving_code, count)){
1.245 misha 383: // optimization for $object.$var
1.247 misha 384: } else
1.238 misha 385: #endif
1.239 misha 386:
387: #ifdef OPTIMIZE_BYTECODE_GET_ELEMENT
1.248 misha 388: if(
389: count>=4
390: && (*diving_code)[0].code==OP::OP_VALUE
391: && (*diving_code)[3].code==OP::OP_GET_ELEMENT
392: ){
393: // optimization
1.239 misha 394: O(*$$,
1.247 misha 395: (PC.in_call_value && count==4)
1.239 misha 396: ? OP::OP_VALUE__GET_ELEMENT_OR_OPERATOR // ^object[ : OP_VALUE+origin+string+OP_GET_ELEMENT => OP_VALUE__GET_ELEMENT_OR_OPERATOR+origin+string
397: : OP::OP_VALUE__GET_ELEMENT // $object : OP_VALUE+origin+string+OP_GET_ELEMENT => OP_VALUE__GET_ELEMENT+origin+string
398: );
399: P(*$$, *diving_code, 1/*offset*/, 2/*limit*/); // copy origin+value
1.247 misha 400: if(count>4)
401: P(*$$, *diving_code, 4); // copy tail
1.239 misha 402: } else {
403: O(*$$, OP::OP_WITH_READ); /* stack: starting context */
404: P(*$$, *diving_code);
405: }
1.233 misha 406: #else
1.247 misha 407: {
1.238 misha 408: O(*$$, OP::OP_WITH_READ); /* stack: starting context */
1.179 paf 409:
1.238 misha 410: // ^if OP_ELEMENT => ^if OP_ELEMENT_OR_OPERATOR
411: // optimized OP_VALUE+origin+string+OP_GET_ELEMENT. => OP_VALUE+origin+string+OP_GET_ELEMENT_OR_OPERATOR.
1.239 misha 412: if(PC.in_call_value && count==4)
413: diving_code->put(count-1, OP::OP_GET_ELEMENT_OR_OPERATOR);
1.206 paf 414: P(*$$, *diving_code);
1.239 misha 415: }
1.233 misha 416: #endif
1.22 paf 417: /* diving code; stack: current context */
1.1 paf 418: };
1.206 paf 419: name_without_curly_rdive_class: class_prefix name_without_curly_rdive_code { $$=$1; P(*$$, *$2) };
420: name_without_curly_rdive_code: name_advance2 | name_path name_advance2 { $$=$1; P(*$$, *$2) };
1.1 paf 421:
422: /* put */
423:
1.81 paf 424: put: '$' name_expr_wdive construct {
1.241 misha 425: $$=N();
1.244 misha 426: #ifdef OPTIMIZE_BYTECODE_CONSTRUCT
427: if(maybe_optimize_construct(*$$, *$2, *$3)){
1.246 misha 428: // $a(expr), $.a(expr), $a[value], $.a[value], $self.a[value], $self.a(expr)
1.241 misha 429: } else
430: #endif
431: {
432: P(*$$, *$2); /* stack: context,name */
433: P(*$$, *$3); /* stack: context,name,constructor_value */
434: }
1.20 paf 435: };
1.44 paf 436: name_expr_wdive:
1.157 parser 437: name_expr_wdive_root
438: | name_expr_wdive_write
1.44 paf 439: | name_expr_wdive_class;
1.157 parser 440: name_expr_wdive_root: name_expr_dive_code {
1.206 paf 441: $$=N();
1.238 misha 442: YYSTYPE diving_code=$1;
1.247 misha 443: size_t count=diving_code->count();
444:
445: if(maybe_make_self(*$$, *diving_code, count)) {
446: // $self.
447: } else
448: #ifdef OPTIMIZE_BYTECODE_GET_ELEMENT
449: if(
450: count>=4
451: && (*diving_code)[0].code==OP::OP_VALUE
452: && (*diving_code)[3].code==OP::OP_GET_ELEMENT
453: ){
454: O(*$$, OP::OP_WITH_ROOT__VALUE__GET_ELEMENT);
455: P(*$$, *diving_code, 1/*offset*/, 2/*limit*/); // copy origin+value
456: if(count>4)
457: P(*$$, *diving_code, 4); // tail
458: } else
459: #endif
460: {
1.229 misha 461: O(*$$, OP::OP_WITH_ROOT); /* stack: starting context */
1.206 paf 462: P(*$$, *diving_code);
1.23 paf 463: }
464: /* diving code; stack: current context */
1.156 parser 465: };
1.157 parser 466: name_expr_wdive_write: '.' name_expr_dive_code {
1.206 paf 467: $$=N();
1.229 misha 468: O(*$$, OP::OP_WITH_WRITE); /* stack: starting context */
1.206 paf 469: P(*$$, *$2); /* diving code; stack: context,name */
1.20 paf 470: };
1.206 paf 471: name_expr_wdive_class: class_prefix name_expr_dive_code { $$=$1; P(*$$, *$2) };
1.20 paf 472:
1.244 misha 473: construct:
1.163 parser 474: construct_square
475: | construct_round
476: | construct_curly
1.149 parser 477: ;
1.211 paf 478: construct_square: '[' {
479: // allow $result_or_other_variable[ letters here any time ]
480: *reinterpret_cast<bool*>(&$$)=PC.explicit_result; PC.explicit_result=false;
481: } any_constructor_code_value {
1.213 paf 482: PC.explicit_result=*reinterpret_cast<bool*>(&$2);
1.211 paf 483: } ']' {
1.149 parser 484: // stack: context, name
1.211 paf 485: $$=$3; // stack: context, name, value
1.229 misha 486: O(*$$, OP::OP_CONSTRUCT_VALUE); /* value=pop; name=pop; context=pop; construct(context,name,value) */
1.81 paf 487: }
488: ;
1.149 parser 489: construct_round: '(' expr_value ')' {
1.206 paf 490: $$=N();
1.229 misha 491: O(*$$, OP::OP_PREPARE_TO_EXPRESSION);
1.149 parser 492: // stack: context, name
1.206 paf 493: P(*$$, *$2); // stack: context, name, value
1.229 misha 494: O(*$$, OP::OP_CONSTRUCT_EXPR); /* value=pop->as_expr_result; name=pop; context=pop; construct(context,name,value) */
1.81 paf 495: }
1.52 paf 496: ;
1.149 parser 497: construct_curly: '{' maybe_codes '}' {
498: // stack: context, name
1.206 paf 499: $$=N();
1.229 misha 500: OA(*$$, OP::OP_CURLY_CODE__CONSTRUCT, $2); /* code=pop; name=pop; context=pop; construct(context,name,junction(code)) */
1.149 parser 501: };
502:
1.55 paf 503: any_constructor_code_value:
1.157 parser 504: void_value /* optimized $var[] case */
1.52 paf 505: | STRING /* optimized $var[STRING] case */
1.55 paf 506: | constructor_code_value /* $var[something complex] */
1.1 paf 507: ;
1.55 paf 508: constructor_code_value: constructor_code {
1.206 paf 509: $$=N();
1.229 misha 510: OA(*$$, OP::OP_OBJECT_POOL, $1); /* stack: empty write context */
1.183 paf 511: /* some code that writes to that context */
512: /* context=pop; stack: context.value() */
1.1 paf 513: };
1.55 paf 514: constructor_code: codes__excluding_sole_str_literal;
1.206 paf 515: codes__excluding_sole_str_literal: action | code codes { $$=$1; P(*$$, *$2) };
1.27 paf 516:
1.1 paf 517: /* call */
518:
1.66 paf 519: call: call_value {
1.238 misha 520: #ifdef OPTIMIZE_BYTECODE_CUT_REM_OPERATOR
521: if((*$1).count())
522: #endif
523: {
524: $$=$1; /* stack: value */
1.249 misha 525: if(!maybe_change_first_opcode(*$$, OP::OP_CONSTRUCT_OBJECT, /*=>*/OP::OP_CONSTRUCT_OBJECT__WRITE))
526: changetail_or_append(*$$,
527: OP::OP_CALL, true, /*=>*/ OP::OP_CALL__WRITE,
528: /*or */OP::OP_WRITE_VALUE); /* value=pop; wcontext.write(value) */
1.238 misha 529: }
1.66 paf 530: };
1.177 paf 531: call_value: '^' {
1.180 paf 532: PC.in_call_value=true;
1.177 paf 533: }
534: call_name {
1.180 paf 535: PC.in_call_value=false;
1.177 paf 536: }
1.154 parser 537: store_params EON { /* ^field.$method{vasya} */
1.238 misha 538: #ifdef OPTIMIZE_BYTECODE_CUT_REM_OPERATOR
1.242 misha 539: #ifdef OPTIMIZE_BYTECODE_GET_ELEMENT
1.238 misha 540: const String* operator_name=LA2S(*$3, 0, OP::OP_VALUE__GET_ELEMENT_OR_OPERATOR);
1.242 misha 541: #else
542: const String* operator_name=LA2S(*$3, 1);
543: #endif
1.249 misha 544: if(operator_name && *operator_name==REM_OPERATOR_NAME){
1.238 misha 545: $$=N();
546: } else
547: #endif
548: {
549: YYSTYPE params_code=$5;
550: if(params_code->count()==3) { // probably [] case. [OP::OP_VALUE+origin+Void]
551: if(Value* value=LA2V(*params_code)) // it is OP_VALUE+origin+value?
552: if(value->is_void()) // value is VVoid?
553: params_code=0; // ^zzz[] case. don't append lone empty param.
554: }
555: /* stack: context, method_junction */
1.249 misha 556:
557: YYSTYPE var_code=$3;
558: if(
559: var_code->count()==8
560: && (*var_code)[0].code==OP::OP_VALUE__GET_CLASS
561: && (*var_code)[3].code==OP::OP_PREPARE_TO_CONSTRUCT_OBJECT
562: && (*var_code)[4].code==OP::OP_VALUE
563: && (*var_code)[7].code==OP::OP_GET_ELEMENT
564: ){
565: yyval=N();
566: O(*$$, OP::OP_CONSTRUCT_OBJECT);
567: P(*$$, *var_code, 1/*offset*/, 2/*limit*/); // class name
568: P(*$$, *var_code, 5/*offset*/, 2/*limit*/); // constructor name
569: OA(*$$, params_code);
570: } else
571: {
572: $$=var_code; /* with_xxx,diving code; stack: context,method_junction */
573: OA(*$$, OP::OP_CALL, params_code); // method_frame=make frame(pop junction); ncontext=pop; call(ncontext,method_frame) stack: value
574: }
1.238 misha 575: }
1.1 paf 576: };
577:
1.43 paf 578: call_name: name_without_curly_rdive;
1.38 paf 579:
1.206 paf 580: store_params: store_param | store_params store_param { $$=$1; P(*$$, *$2) };
1.69 paf 581: store_param:
582: store_square_param
583: | store_round_param
584: | store_curly_param
1.31 paf 585: ;
1.210 paf 586: store_square_param: '[' {
1.211 paf 587: // allow ^call[ letters here any time ]
1.210 paf 588: *reinterpret_cast<bool*>(&$$)=PC.explicit_result; PC.explicit_result=false;
589: } store_code_param_parts {
1.213 paf 590: PC.explicit_result=*reinterpret_cast<bool*>(&$2);
1.210 paf 591: } ']' {$$=$3};
1.69 paf 592: store_round_param: '(' store_expr_param_parts ')' {$$=$2};
1.94 paf 593: store_curly_param: '{' store_curly_param_parts '}' {$$=$2};
1.69 paf 594: store_code_param_parts:
595: store_code_param_part
1.206 paf 596: | store_code_param_parts ';' store_code_param_part { $$=$1; P(*$$, *$3) }
1.69 paf 597: ;
598: store_expr_param_parts:
599: store_expr_param_part
1.206 paf 600: | store_expr_param_parts ';' store_expr_param_part { $$=$1; P(*$$, *$3) }
1.69 paf 601: ;
1.94 paf 602: store_curly_param_parts:
603: store_curly_param_part
1.206 paf 604: | store_curly_param_parts ';' store_curly_param_part { $$=$1; P(*$$, *$3) }
1.94 paf 605: ;
1.120 paf 606: store_code_param_part: code_param_value {
1.32 paf 607: $$=$1;
1.120 paf 608: };
1.214 paf 609: store_expr_param_part: expr_value {
610: YYSTYPE expr_code=$1;
1.215 paf 611: if(expr_code->count()==3
1.234 misha 612: && (*expr_code)[0].code==OP::OP_VALUE) { // optimizing (double/bool/incidently 'string' too) case. [OP::OP_VALUE+origin+Double]. no evaluating
1.214 paf 613: $$=expr_code;
614: } else {
1.238 misha 615: YYSTYPE code=N();
1.229 misha 616: O(*code, OP::OP_PREPARE_TO_EXPRESSION);
1.214 paf 617: P(*code, *expr_code);
1.229 misha 618: O(*code, OP::OP_WRITE_EXPR_RESULT);
1.214 paf 619: $$=N();
1.229 misha 620: OA(*$$, OP::OP_EXPR_CODE__STORE_PARAM, code);
1.214 paf 621: }
1.69 paf 622: };
1.94 paf 623: store_curly_param_part: maybe_codes {
1.206 paf 624: $$=N();
1.229 misha 625: OA(*$$, OP::OP_CURLY_CODE__STORE_PARAM, $1);
1.94 paf 626: };
1.120 paf 627: code_param_value:
1.157 parser 628: void_value /* optimized [;...] case */
1.120 paf 629: | STRING /* optimized [STRING] case */
630: | constructor_code_value /* [something complex] */
631: ;
1.1 paf 632:
633: /* name */
634:
1.206 paf 635: name_expr_dive_code: name_expr_value | name_path name_expr_value { $$=$1; P(*$$, *$2) };
1.1 paf 636:
1.206 paf 637: name_path: name_step | name_path name_step { $$=$1; P(*$$, *$2) };
1.1 paf 638: name_step: name_advance1 '.';
639: name_advance1: name_expr_value {
1.177 paf 640: // we know that name_advance1 not called from ^xxx context
641: // so we'll not check for operator call possibility as we do in name_advance2
642:
1.1 paf 643: /* stack: context */
644: $$=$1; /* stack: context,name */
1.229 misha 645: O(*$$, OP::OP_GET_ELEMENT); /* name=pop; context=pop; stack: context.get_element(name) */
1.1 paf 646: };
647: name_advance2: name_expr_value {
648: /* stack: context */
649: $$=$1; /* stack: context,name */
1.229 misha 650: O(*$$, OP::OP_GET_ELEMENT); /* name=pop; context=pop; stack: context.get_element(name) */
1.1 paf 651: }
1.4 paf 652: | STRING BOGUS
1.1 paf 653: ;
654: name_expr_value:
1.4 paf 655: STRING /* subname_is_const */
1.1 paf 656: | name_expr_subvar_value /* $subname_is_var_value */
1.160 parser 657: | name_expr_with_subvar_value /* xxx$part_of_subname_is_var_value */
1.166 parser 658: | name_square_code_value /* [codes] */
1.1 paf 659: ;
660: name_expr_subvar_value: '$' subvar_ref_name_rdive {
661: $$=$2;
1.229 misha 662: O(*$$, OP::OP_GET_ELEMENT);
1.1 paf 663: };
1.4 paf 664: name_expr_with_subvar_value: STRING subvar_get_writes {
1.238 misha 665: YYSTYPE code;
1.183 paf 666: {
1.206 paf 667: change_string_literal_to_write_string_literal(*(code=$1));
668: P(*code, *$2);
1.183 paf 669: }
1.206 paf 670: $$=N();
1.229 misha 671: OA(*$$, OP::OP_STRING_POOL, code);
1.1 paf 672: };
1.212 paf 673: name_square_code_value: '[' {
674: // allow $result_or_other_variable[ letters here any time ]
675: *reinterpret_cast<bool*>(&$$)=PC.explicit_result; PC.explicit_result=false;
676: } codes {
1.213 paf 677: PC.explicit_result=*reinterpret_cast<bool*>(&$2);
1.212 paf 678: } ']' {
1.206 paf 679: $$=N();
1.229 misha 680: OA(*$$, OP::OP_OBJECT_POOL, $3); /* stack: empty write context */
1.183 paf 681: /* some code that writes to that context */
682: /* context=pop; stack: context.value() */
1.160 parser 683: };
1.154 parser 684: subvar_ref_name_rdive: STRING {
1.206 paf 685: $$=N();
1.229 misha 686: O(*$$, OP::OP_WITH_READ);
1.206 paf 687: P(*$$, *$1);
1.1 paf 688: };
1.206 paf 689: subvar_get_writes: subvar__get_write | subvar_get_writes subvar__get_write { $$=$1; P(*$$, *$2) };
1.1 paf 690: subvar__get_write: '$' subvar_ref_name_rdive {
691: $$=$2;
1.229 misha 692: O(*$$, OP::OP_GET_ELEMENT__WRITE);
1.42 paf 693: };
694:
1.154 parser 695: class_prefix:
696: class_static_prefix
697: | class_constructor_prefix
698: ;
1.155 parser 699: class_static_prefix: STRING ':' {
700: $$=$1; // stack: class name string
1.206 paf 701: if(*LA2S(*$$) == BASE_NAME) { // pseudo BASE class
702: if(VStateless_class* base=PC.cclass->base_class()) {
703: change_string_literal_value(*$$, base->name());
1.189 paf 704: } else {
705: strcpy(PC.error, "no base class declared");
706: YYERROR;
707: }
708: }
1.233 misha 709: #ifdef OPTIMIZE_BYTECODE_GET_CLASS
1.238 misha 710: // optimized OP_VALUE+origin+string+OP_GET_CLASS => OP_VALUE__GET_CLASS+origin+string
1.245 misha 711: maybe_change_first_opcode(*$$, OP::OP_VALUE, OP::OP_VALUE__GET_CLASS)
1.233 misha 712: #else
1.229 misha 713: O(*$$, OP::OP_GET_CLASS);
1.233 misha 714: #endif
1.155 parser 715: };
716: class_constructor_prefix: class_static_prefix ':' {
1.154 parser 717: $$=$1;
1.180 paf 718: if(!PC.in_call_value) {
1.154 parser 719: strcpy(PC.error, ":: not allowed here");
720: YYERROR;
721: }
1.229 misha 722: O(*$$, OP::OP_PREPARE_TO_CONSTRUCT_OBJECT);
1.1 paf 723: };
724:
1.53 paf 725:
1.56 paf 726: /* expr */
1.53 paf 727:
1.214 paf 728: expr_value: expr;
1.56 paf 729: expr:
1.214 paf 730: double_or_STRING
1.216 paf 731: | true_value
732: | false_value
1.64 paf 733: | get_value
1.66 paf 734: | call_value
1.216 paf 735: | '"' string_inside_quotes_value '"' { $$ = $2 }
736: | '\'' string_inside_quotes_value '\'' { $$ = $2 }
1.60 paf 737: | '(' expr ')' { $$ = $2; }
738: /* stack: operand // stack: @operand */
1.229 misha 739: | '-' expr %prec NUNARY { $$=$2; O(*$$, OP::OP_NEG) }
1.202 paf 740: | '+' expr %prec NUNARY { $$=$2 }
1.229 misha 741: | '~' expr { $$=$2; O(*$$, OP::OP_INV) }
742: | '!' expr { $$=$2; O(*$$, OP::OP_NOT) }
743: | "def" expr { $$=$2; O(*$$, OP::OP_DEF) }
744: | "in" expr { $$=$2; O(*$$, OP::OP_IN) }
745: | "-f" expr { $$=$2; O(*$$, OP::OP_FEXISTS) }
746: | "-d" expr { $$=$2; O(*$$, OP::OP_DEXISTS) }
1.60 paf 747: /* stack: a,b // stack: a@b */
1.229 misha 748: | expr '-' expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_SUB) }
749: | expr '+' expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_ADD) }
750: | expr '*' expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_MUL) }
751: | expr '/' expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_DIV) }
752: | expr '%' expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_MOD) }
753: | expr '\\' expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_INTDIV) }
754: | expr "<<" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_BIN_SL) }
755: | expr ">>" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_BIN_SR) }
756: | expr '&' expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_BIN_AND) }
757: | expr '|' expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_BIN_OR) }
758: | expr "!|" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_BIN_XOR) }
759: | expr "&&" expr { $$=$1; OA(*$$, OP::OP_NESTED_CODE, $3); O(*$$, OP::OP_LOG_AND) }
760: | expr "||" expr { $$=$1; OA(*$$, OP::OP_NESTED_CODE, $3); O(*$$, OP::OP_LOG_OR) }
761: | expr "!||" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_LOG_XOR) }
762: | expr '<' expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_NUM_LT) }
763: | expr '>' expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_NUM_GT) }
764: | expr "<=" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_NUM_LE) }
765: | expr ">=" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_NUM_GE) }
766: | expr "==" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_NUM_EQ) }
767: | expr "!=" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_NUM_NE) }
768: | expr "lt" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_STR_LT) }
769: | expr "gt" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_STR_GT) }
770: | expr "le" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_STR_LE) }
771: | expr "ge" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_STR_GE) }
772: | expr "eq" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_STR_EQ) }
773: | expr "ne" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_STR_NE) }
774: | expr "is" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_IS) }
1.56 paf 775: ;
1.214 paf 776:
777: double_or_STRING: STRING {
1.238 misha 778: // optimized OP_STRING => OP_VALUE for doubles
1.214 paf 779: maybe_change_string_literal_to_double_literal(*($$=$1));
780: };
1.55 paf 781:
1.65 paf 782: string_inside_quotes_value: maybe_codes {
1.238 misha 783: #ifdef OPTIMIZE_BYTECODE_STRING_POOL
784: // it brakes ^if(" 09 "){...}
785: YYSTYPE code=$1;
786: $$=N();
1.239 misha 787: if(code->count()==3 && maybe_change_first_opcode(*code, OP::OP_STRING__WRITE, OP::OP_VALUE)){
1.238 misha 788: // optimized OP_STRING__WRITE+origin+value => OP_VALUE+origin+value without starting OP_STRING_POOL
789: P(*$$, *code);
790: } else {
791: OA(*$$, OP::OP_STRING_POOL, code); /* stack: empty write context */
792: }
793: #else
1.206 paf 794: $$=N();
1.229 misha 795: OA(*$$, OP::OP_STRING_POOL, $1); /* stack: empty write context */
1.238 misha 796: #endif
1.183 paf 797: /* some code that writes to that context */
798: /* context=pop; stack: context.get_string() */
1.53 paf 799: };
1.1 paf 800:
1.27 paf 801: /* basics */
1.1 paf 802:
1.81 paf 803: write_string: STRING {
1.238 misha 804: // optimized OP_STRING+OP_WRITE_VALUE => OP_STRING__WRITE
1.209 paf 805: change_string_literal_to_write_string_literal(*($$=$1))
1.54 paf 806: };
807:
1.216 paf 808: void_value: /* empty */ { $$=VL(/*we know that we will not change it*/const_cast<VVoid*>(&vvoid), 0, 0, 0) }
809: true_value: "true" { $$ = VL(/*we know that we will not change it*/const_cast<VBool*>(&vtrue), 0, 0, 0) }
810: false_value: "false" { $$ = VL(/*we know that we will not change it*/const_cast<VBool*>(&vfalse), 0, 0, 0) }
811:
1.206 paf 812: empty: /* empty */ { $$=N() };
1.1 paf 813:
814: %%
1.105 paf 815: #endif
1.1 paf 816:
817: /*
818: 000$111(2222)00
819: 000$111{3333}00
1.9 paf 820: $,^: push,=0
1.1 paf 821: 1:( { break=pop
822: 2:( ) pop
823: 3:{ } pop
824:
825: 000^111(2222)4444{33333}4000
1.9 paf 826: $,^: push,=0
1.1 paf 827: 1:( { break=pop
828: 2:( )=4
829: 3:{ }=4
830: 4:[^({]=pop
831: */
832:
1.206 paf 833: inline void ungetc(Parse_control& pc, uint last_line_end_col) {
834: pc.source--;
835: if(pc.pos.col==0) {
836: --pc.pos.line; pc.pos.col=last_line_end_col;
837: } else
838: --pc.pos.col;
839:
840: }
841: static int yylex(YYSTYPE *lvalp, void *apc) {
842: register Parse_control& pc=*static_cast<Parse_control*>(apc);
843:
844: #define lexical_brackets_nestage pc.brackets_nestages[pc.ls_sp]
1.48 paf 845: #define RC {result=c; goto break2; }
1.1 paf 846:
1.206 paf 847: register int c;
848: int result;
1.1 paf 849:
1.206 paf 850: if(pc.pending_state) {
851: result=pc.pending_state;
852: pc.pending_state=0;
1.1 paf 853: return result;
854: }
855:
1.206 paf 856: const char *begin=pc.source;
857: Pos begin_pos=pc.pos;
1.91 paf 858: const char *end;
1.67 paf 859: int skip_analized=0;
1.50 paf 860: while(true) {
1.206 paf 861: c=*(end=(pc.source++));
862: // fprintf(stderr, "\nchar: %c %02X; nestage: %d, sp=%d", c, c, lexical_brackets_nestage, pc.sp);
1.1 paf 863:
1.208 paf 864: if(c=='\n')
1.206 paf 865: pc.pos_next_line();
1.208 paf 866: else
1.206 paf 867: pc.pos_next_c(c);
1.208 paf 868: // fprintf(stderr, "\nchar: %c file(%d:%d)", c, pc.pos.line, pc.pos.col);
1.73 paf 869:
1.208 paf 870: if(pc.pos.col==0+1 && c=='@') {
1.206 paf 871: if(pc.ls==LS_DEF_SPECIAL_BODY) {
1.175 paf 872: // @SPECIAL
873: // ...
874: // @<here =
1.206 paf 875: pop_LS(pc); // exiting from LS_DEF_SPECIAL_BODY state
1.175 paf 876: } // continuing checks
1.206 paf 877: if(pc.ls==LS_USER) {
878: push_LS(pc, LS_DEF_NAME);
1.171 parser 879: RC;
1.175 paf 880: } else // @ in first column inside some code [when could that be?]
1.171 parser 881: result=BAD_METHOD_DECL_START;
882: goto break2;
1.209 paf 883: }
884: if(c=='^') {
1.206 paf 885: if(pc.ls==LS_METHOD_AFTER) {
1.203 paf 886: // handle after-method situation
1.206 paf 887: pop_LS(pc);
1.203 paf 888: result=EON;
889: skip_analized=-1; // return to punctuation afterwards to assure it's literality
890: goto break2;
891: }
1.206 paf 892: switch(pc.ls) {
1.169 parser 893: case LS_EXPRESSION_VAR_NAME_WITH_COLON:
894: case LS_EXPRESSION_VAR_NAME_WITHOUT_COLON:
895: case LS_VAR_NAME_SIMPLE_WITH_COLON:
896: case LS_VAR_NAME_SIMPLE_WITHOUT_COLON:
897: case LS_VAR_NAME_CURLY:
898: case LS_METHOD_NAME:
1.194 paf 899: case LS_USER_COMMENT:
1.169 parser 900: case LS_DEF_COMMENT:
901: // no literals in names, please
902: break;
903: default:
1.206 paf 904: switch(*pc.source) {
1.165 parser 905: // ^escaping some punctuators
1.228 misha 906: case '^': case '$': case ';': case '@':
1.126 paf 907: case '(': case ')':
1.48 paf 908: case '[': case ']':
909: case '{': case '}':
1.172 parser 910: case '"': case ':':
1.40 paf 911: if(end!=begin) {
1.206 paf 912: if(!pc.string_start)
913: pc.string_start=begin_pos;
1.40 paf 914: // append piece till ^
1.206 paf 915: pc.string.append_strdup_know_length(begin, end-begin);
1.40 paf 916: }
1.63 paf 917: // reset piece 'begin' position & line
1.206 paf 918: begin=pc.source; // ->punctuation
919: begin_pos=pc.pos;
1.203 paf 920: // skip over _ after ^
1.206 paf 921: pc.source++; pc.pos.col++;
1.203 paf 922: // skip analysis = forced literal
923: continue;
1.114 paf 924:
925: // converting ^#HH into char(hex(HH))
926: case '#':
927: if(end!=begin) {
1.206 paf 928: if(!pc.string_start)
929: pc.string_start=begin_pos;
1.114 paf 930: // append piece till ^
1.206 paf 931: pc.string.append_strdup_know_length(begin, end-begin);
1.114 paf 932: }
933: // #HH ?
1.228 misha 934: if(pc.source[1] && isxdigit(pc.source[1]) && pc.source[2] && isxdigit(pc.source[2])) {
1.218 paf 935: char c=(char)(
1.206 paf 936: hex_value[(unsigned char)pc.source[1]]*0x10+
1.218 paf 937: hex_value[(unsigned char)pc.source[2]]);
1.206 paf 938: if(c==0) {
1.114 paf 939: result=BAD_HEX_LITERAL;
940: goto break2; // wrong hex value[no ^#00 chars allowed]: bail out
941: }
942: // append char(hex(HH))
1.206 paf 943: pc.string.append(c);
1.114 paf 944: // skip over ^#HH
1.206 paf 945: pc.source+=3;
946: pc.pos.col+=3;
1.114 paf 947: // reset piece 'begin' position & line
1.206 paf 948: begin=pc.source; // ->after ^#HH
949: begin_pos=pc.pos;
1.203 paf 950: // skip analysis = forced literal
1.114 paf 951: continue;
952: }
1.228 misha 953: // just escaped char
954: // reset piece 'begin' position & line
955: begin=pc.source;
956: begin_pos=pc.pos;
957: // skip over _ after ^
958: pc.source++; pc.pos.col++;
959: // skip analysis = forced literal
960: continue;
1.1 paf 961: }
1.169 parser 962: break;
1.203 paf 963: }
1.169 parser 964: }
1.113 paf 965: // #comment start skipping
1.206 paf 966: if(c=='#' && pc.pos.col==1) {
1.112 paf 967: if(end!=begin) {
1.206 paf 968: if(!pc.string_start)
969: pc.string_start=begin_pos;
1.112 paf 970: // append piece till #
1.206 paf 971: pc.string.append_strdup_know_length(begin, end-begin);
1.112 paf 972: }
973: // fall into COMMENT lexical state [wait for \n]
1.206 paf 974: push_LS(pc, LS_USER_COMMENT);
1.175 paf 975: continue;
1.112 paf 976: }
1.206 paf 977: switch(pc.ls) {
1.10 paf 978:
979: // USER'S = NOT OURS
1.1 paf 980: case LS_USER:
1.206 paf 981: case LS_NAME_SQUARE_PART: // name.[here].xxx
982: if(pc.trim_bof)
1.153 parser 983: switch(c) {
984: case '\n': case ' ': case '\t':
1.206 paf 985: begin=pc.source;
986: begin_pos=pc.pos;
1.152 parser 987: continue; // skip it
1.153 parser 988: default:
1.206 paf 989: pc.trim_bof=false;
1.152 parser 990: }
1.48 paf 991: switch(c) {
992: case '$':
1.206 paf 993: push_LS(pc, LS_VAR_NAME_SIMPLE_WITH_COLON);
1.48 paf 994: RC;
995: case '^':
1.206 paf 996: push_LS(pc, LS_METHOD_NAME);
1.48 paf 997: RC;
1.166 parser 998: case ']':
1.206 paf 999: if(pc.ls==LS_NAME_SQUARE_PART)
1.166 parser 1000: if(--lexical_brackets_nestage==0) {// $name.[co<]?>de<]?>
1.206 paf 1001: pop_LS(pc); // $name.[co<]>de<]!>
1.166 parser 1002: RC;
1003: }
1.160 parser 1004: break;
1.166 parser 1005: case '[': // $name.[co<[>de]
1.206 paf 1006: if(pc.ls==LS_NAME_SQUARE_PART)
1.166 parser 1007: lexical_brackets_nestage++;
1.161 parser 1008: break;
1.112 paf 1009: }
1.209 paf 1010: if(pc.explicit_result && c)
1011: switch(c) {
1012: case '\n': case ' ': case '\t':
1013: begin=pc.source;
1014: begin_pos=pc.pos;
1015: continue; // skip it
1016: default:
1017: result=BAD_NONWHITESPACE_CHARACTER_IN_EXPLICIT_RESULT_MODE;
1018: goto break2;
1019: }
1.112 paf 1020: break;
1021:
1022: // #COMMENT
1.194 paf 1023: case LS_USER_COMMENT:
1.112 paf 1024: if(c=='\n') {
1025: // skip comment
1.206 paf 1026: begin=pc.source;
1027: begin_pos=pc.pos;
1.112 paf 1028:
1.206 paf 1029: pop_LS(pc);
1.112 paf 1030: continue;
1.1 paf 1031: }
1.48 paf 1032: break;
1033:
1034: // STRING IN EXPRESSION
1.145 parser 1035: case LS_EXPRESSION_STRING_QUOTED:
1036: case LS_EXPRESSION_STRING_APOSTROFED:
1.48 paf 1037: switch(c) {
1038: case '"':
1.145 parser 1039: case '\'':
1040: if(
1.206 paf 1041: pc.ls == LS_EXPRESSION_STRING_QUOTED && c=='"' ||
1042: pc.ls == LS_EXPRESSION_STRING_APOSTROFED && c=='\'') {
1043: pop_LS(pc); //"abc". | 'abc'.
1.145 parser 1044: RC;
1045: }
1046: break;
1.48 paf 1047: case '$':
1.206 paf 1048: push_LS(pc, LS_VAR_NAME_SIMPLE_WITH_COLON);
1.48 paf 1049: RC;
1050: case '^':
1.206 paf 1051: push_LS(pc, LS_METHOD_NAME);
1.48 paf 1052: RC;
1.10 paf 1053: }
1054: break;
1055:
1056: // METHOD DEFINITION
1057: case LS_DEF_NAME:
1.48 paf 1058: switch(c) {
1059: case '[':
1.206 paf 1060: pc.ls=LS_DEF_PARAMS;
1.48 paf 1061: RC;
1062: case '\n':
1.206 paf 1063: pc.ls=LS_DEF_SPECIAL_BODY;
1.48 paf 1064: RC;
1.10 paf 1065: }
1066: break;
1.48 paf 1067:
1.10 paf 1068: case LS_DEF_PARAMS:
1.48 paf 1069: switch(c) {
1.192 paf 1070: case '$': // common error
1.193 paf 1071: result=BAD_METHOD_PARAMETER_NAME_CHARACTER;
1072: goto break2;
1.48 paf 1073: case ';':
1074: RC;
1075: case ']':
1.206 paf 1076: pc.ls=*pc.source=='['?LS_DEF_LOCALS:LS_DEF_COMMENT;
1.48 paf 1077: RC;
1.49 paf 1078: case '\n': // wrong. bailing out
1.206 paf 1079: pop_LS(pc);
1.48 paf 1080: RC;
1.10 paf 1081: }
1082: break;
1.48 paf 1083:
1.10 paf 1084: case LS_DEF_LOCALS:
1.48 paf 1085: switch(c) {
1086: case '[':
1087: case ';':
1088: RC;
1089: case ']':
1.206 paf 1090: pc.ls=LS_DEF_COMMENT;
1.48 paf 1091: RC;
1092: case '\n': // wrong. bailing out
1.206 paf 1093: pop_LS(pc);
1.48 paf 1094: RC;
1.10 paf 1095: }
1096: break;
1.48 paf 1097:
1.10 paf 1098: case LS_DEF_COMMENT:
1099: if(c=='\n') {
1.206 paf 1100: pop_LS(pc);
1.48 paf 1101: RC;
1.37 paf 1102: }
1103: break;
1104:
1.48 paf 1105: case LS_DEF_SPECIAL_BODY:
1.175 paf 1106: if(c=='\n')
1.48 paf 1107: RC;
1108: break;
1109:
1110: // (EXPRESSION)
1.69 paf 1111: case LS_VAR_ROUND:
1112: case LS_METHOD_ROUND:
1.48 paf 1113: switch(c) {
1114: case ')':
1115: if(--lexical_brackets_nestage==0)
1.206 paf 1116: if(pc.ls==LS_METHOD_ROUND) // method round param ended
1117: pc.ls=LS_METHOD_AFTER; // look for method end
1118: else // pc.ls==LS_VAR_ROUND // variable constructor ended
1119: pop_LS(pc); // return to normal life
1.48 paf 1120: RC;
1.194 paf 1121: case '#': // comment start skipping
1122: if(end!=begin) {
1.206 paf 1123: if(!pc.string_start)
1124: pc.string_start=begin_pos;
1.194 paf 1125: // append piece till #
1.206 paf 1126: pc.string.append_strdup_know_length(begin, end-begin);
1.194 paf 1127: }
1128: // fall into COMMENT lexical state [wait for \n]
1.206 paf 1129: push_LS(pc, LS_EXPRESSION_COMMENT);
1.194 paf 1130: lexical_brackets_nestage=1;
1131: continue;
1.48 paf 1132: case '$':
1.206 paf 1133: push_LS(pc, LS_EXPRESSION_VAR_NAME_WITH_COLON);
1.48 paf 1134: RC;
1135: case '^':
1.206 paf 1136: push_LS(pc, LS_METHOD_NAME);
1.48 paf 1137: RC;
1138: case '(':
1139: lexical_brackets_nestage++;
1140: RC;
1.67 paf 1141: case '-':
1.206 paf 1142: switch(*pc.source) {
1.127 paf 1143: case 'f': // -f
1.67 paf 1144: skip_analized=1;
1145: result=FEXISTS;
1.127 paf 1146: goto break2;
1147: case 'd': // -d
1148: skip_analized=1;
1149: result=DEXISTS;
1150: goto break2;
1.191 paf 1151: default: // minus
1.67 paf 1152: result=c;
1.127 paf 1153: goto break2;
1154: }
1.67 paf 1155: goto break2;
1.173 paf 1156: case '+': case '*': case '/': case '%': case '\\':
1.58 paf 1157: case '~':
1.48 paf 1158: case ';':
1159: RC;
1.193 paf 1160: case '&': case '|':
1.206 paf 1161: if(*pc.source==c) { // && ||
1.193 paf 1162: result=c=='&'?LAND:LOR;
1.67 paf 1163: skip_analized=1;
1.58 paf 1164: } else
1165: result=c;
1166: goto break2;
1.193 paf 1167: case '!':
1.206 paf 1168: switch(pc.source[0]) {
1.193 paf 1169: case '|': // !| !||
1170: skip_analized=1;
1.206 paf 1171: if(pc.source[1]=='|') {
1.193 paf 1172: skip_analized++;
1173: result=LXOR;
1174: } else
1175: result=NXOR;
1176: goto break2;
1177: case '=': // !=
1178: skip_analized=1;
1179: result=NNE;
1180: goto break2;
1181: }
1182: RC;
1.195 paf 1183:
1184: case '<': // <<, <=, <
1.206 paf 1185: switch(*pc.source) {
1.195 paf 1186: case '<': // <[<]
1187: skip_analized=1; result=NSL; break;
1188: case '=': // <[=]
1189: skip_analized=1; result=NLE; break;
1190: default: // <[]
1191: result=c; break;
1192: }
1193: goto break2;
1194: case '>': // >>, >=, >
1.206 paf 1195: switch(*pc.source) {
1.195 paf 1196: case '>': // >[>]
1197: skip_analized=1; result=NSR; break;
1198: case '=': // >[=]
1199: skip_analized=1; result=NGE; break;
1200: default: // >[]
1201: result=c; break;
1202: }
1203: goto break2;
1204: case '=': // ==
1.206 paf 1205: switch(*pc.source) {
1.195 paf 1206: case '=': // =[=]
1207: skip_analized=1; result=NEQ; break;
1208: default: // =[]
1209: result=c; break; // not used now
1210: }
1.58 paf 1211: goto break2;
1.195 paf 1212:
1.48 paf 1213: case '"':
1.206 paf 1214: push_LS(pc, LS_EXPRESSION_STRING_QUOTED);
1.145 parser 1215: RC;
1216: case '\'':
1.206 paf 1217: push_LS(pc, LS_EXPRESSION_STRING_APOSTROFED);
1.48 paf 1218: RC;
1.50 paf 1219: case 'l': case 'g': case 'e': case 'n':
1.51 paf 1220: if(end==begin) // right after whitespace
1.206 paf 1221: if(isspace(pc.source[1])) {
1222: switch(*pc.source) {
1.117 paf 1223: // case '?': // ok [and bad cases, yacc would bark at them]
1224: case 't': // lt gt [et nt]
1225: result=c=='l'?SLT:c=='g'?SGT:BAD_STRING_COMPARISON_OPERATOR;
1226: skip_analized=1;
1227: goto break2;
1228: case 'e': // le ge ne [ee]
1229: result=c=='l'?SLE:c=='g'?SGE:c=='n'?SNE:BAD_STRING_COMPARISON_OPERATOR;
1230: skip_analized=1;
1231: goto break2;
1232: case 'q': // eq [lq gq nq]
1233: result=c=='e'?SEQ:BAD_STRING_COMPARISON_OPERATOR;
1234: skip_analized=1;
1235: goto break2;
1236: }
1.67 paf 1237: }
1238: break;
1239: case 'i':
1240: if(end==begin) // right after whitespace
1.206 paf 1241: if(isspace(pc.source[1])) {
1242: switch(pc.source[0]) {
1.117 paf 1243: case 'n': // in
1.95 paf 1244: skip_analized=1;
1245: result=IN;
1246: goto break2;
1.117 paf 1247: case 's': // is
1.95 paf 1248: skip_analized=1;
1249: result=IS;
1250: goto break2;
1251: }
1.67 paf 1252: }
1253: break;
1254: case 'd':
1255: if(end==begin) // right after whitespace
1.206 paf 1256: if(pc.source[0]=='e' && pc.source[1]=='f') { // def
1.225 misha 1257: switch(pc.source[2]){
1258: case ' ': case '\t': case '\n': case '"': case '\'': case '^': case '$': // non-quoted string without whitespace after 'def' is not allowed
1259: skip_analized=2;
1260: result=DEF;
1261: goto break2;
1262: }
1263: // error: incorrect char after 'def'
1.50 paf 1264: }
1.48 paf 1265: break;
1.216 paf 1266: case 't':
1267: if(end==begin) // right after whitespace
1.225 misha 1268: if(pc.source[0]=='r' && pc.source[1]=='u' && pc.source[2]=='e') { // true
1.216 paf 1269: skip_analized=3;
1270: result=LITERAL_TRUE;
1271: goto break2;
1272: }
1273: break;
1274: case 'f':
1275: if(end==begin) // right after whitespace
1.225 misha 1276: if(pc.source[0]=='a' && pc.source[1]=='l' && pc.source[2]=='s' && pc.source[3]=='e') { // false
1.216 paf 1277: skip_analized=4;
1278: result=LITERAL_FALSE;
1279: goto break2;
1280: }
1281: break;
1.48 paf 1282: case ' ': case '\t': case '\n':
1.63 paf 1283: if(end!=begin) { // there were a string after previous operator?
1284: result=0; // return that string
1285: goto break2;
1.48 paf 1286: }
1.63 paf 1287: // that's a leading|traling space or after-operator-space
1288: // ignoring it
1289: // reset piece 'begin' position & line
1.206 paf 1290: begin=pc.source; // after whitespace char
1291: begin_pos=pc.pos;
1.48 paf 1292: continue;
1.1 paf 1293: }
1294: break;
1.194 paf 1295: case LS_EXPRESSION_COMMENT:
1296: if(c=='(')
1297: lexical_brackets_nestage++;
1298:
1.206 paf 1299: switch(*pc.source) {
1.194 paf 1300: case '\n': case ')':
1.206 paf 1301: if(*pc.source==')')
1.194 paf 1302: if(--lexical_brackets_nestage!=0)
1303: continue;
1304:
1305: // skip comment
1.206 paf 1306: begin=pc.source;
1307: begin_pos=pc.pos;
1.194 paf 1308:
1.206 paf 1309: pop_LS(pc);
1.194 paf 1310: continue;
1311: }
1312: break;
1.1 paf 1313:
1.10 paf 1314: // VARIABLE GET/PUT/WITH
1.166 parser 1315: case LS_VAR_NAME_SIMPLE_WITH_COLON:
1316: case LS_VAR_NAME_SIMPLE_WITHOUT_COLON:
1317: case LS_EXPRESSION_VAR_NAME_WITH_COLON:
1318: case LS_EXPRESSION_VAR_NAME_WITHOUT_COLON:
1319: if(
1.206 paf 1320: pc.ls==LS_EXPRESSION_VAR_NAME_WITH_COLON ||
1321: pc.ls==LS_EXPRESSION_VAR_NAME_WITHOUT_COLON) {
1.181 paf 1322: // name in expr ends also before
1.48 paf 1323: switch(c) {
1.181 paf 1324: // expression minus
1.92 paf 1325: case '-':
1.181 paf 1326: // expression integer division
1327: case '\\':
1.206 paf 1328: pop_LS(pc);
1329: pc.ungetc();
1.48 paf 1330: result=EON;
1331: goto break2;
1332: }
1333: }
1.166 parser 1334: if(
1.206 paf 1335: pc.ls==LS_VAR_NAME_SIMPLE_WITHOUT_COLON ||
1336: pc.ls==LS_EXPRESSION_VAR_NAME_WITHOUT_COLON) {
1.142 parser 1337: // name already has ':', stop before next
1338: switch(c) {
1339: case ':':
1.206 paf 1340: pop_LS(pc);
1341: pc.ungetc();
1.142 parser 1342: result=EON;
1343: goto break2;
1344: }
1345: }
1.48 paf 1346: switch(c) {
1347: case 0:
1348: case ' ': case '\t': case '\n':
1349: case ';':
1.126 paf 1350: case ']': case '}': case ')':
1351: case '"': case '\'':
1.139 parser 1352: case '<': case '>': // these stand for HTML brackets AND expression binary ops
1.92 paf 1353: case '+': case '*': case '/': case '%':
1354: case '&': case '|':
1355: case '=': case '!':
1.99 paf 1356: // common delimiters
1.190 paf 1357: case ',': case '?': case '#':
1.220 paf 1358: // mysql column separators
1359: case '`':
1.139 parser 1360: // before call
1361: case '^':
1.206 paf 1362: pop_LS(pc);
1363: pc.ungetc();
1.13 paf 1364: result=EON;
1.1 paf 1365: goto break2;
1.48 paf 1366: case '[':
1.162 parser 1367: // $name.<[>code]
1.206 paf 1368: if(pc.pos.col>1/*not first column*/ && (
1.163 parser 1369: end[-1]=='$'/*was start of get*/ ||
1370: end[-1]==':'/*was class name delim */ ||
1371: end[-1]=='.'/*was name delim */
1.162 parser 1372: )) {
1.206 paf 1373: push_LS(pc, LS_NAME_SQUARE_PART);
1.162 parser 1374: lexical_brackets_nestage=1;
1375: RC;
1376: }
1.206 paf 1377: pc.ls=LS_VAR_SQUARE;
1.1 paf 1378: lexical_brackets_nestage=1;
1.48 paf 1379: RC;
1380: case '{':
1381: if(begin==end) { // ${name}, no need of EON, switching LS
1.206 paf 1382: pc.ls=LS_VAR_NAME_CURLY;
1.48 paf 1383: } else {
1.206 paf 1384: pc.ls=LS_VAR_CURLY;
1.48 paf 1385: lexical_brackets_nestage=1;
1386: }
1.69 paf 1387:
1.48 paf 1388: RC;
1389: case '(':
1.206 paf 1390: pc.ls=LS_VAR_ROUND;
1.1 paf 1391: lexical_brackets_nestage=1;
1.48 paf 1392: RC;
1393: case '.': // name part delim
1394: case '$': // name part subvar
1.160 parser 1395: case ':': // class<:>name
1.166 parser 1396: // go to _WITHOUT_COLON state variant...
1.206 paf 1397: if(pc.ls==LS_VAR_NAME_SIMPLE_WITH_COLON)
1398: pc.ls=LS_VAR_NAME_SIMPLE_WITHOUT_COLON;
1399: else if(pc.ls==LS_EXPRESSION_VAR_NAME_WITH_COLON)
1400: pc.ls=LS_EXPRESSION_VAR_NAME_WITHOUT_COLON;
1.166 parser 1401: // ...stop before next ':'
1.48 paf 1402: RC;
1.1 paf 1403: }
1404: break;
1.48 paf 1405:
1.1 paf 1406: case LS_VAR_NAME_CURLY:
1.48 paf 1407: switch(c) {
1.162 parser 1408: case '[':
1.166 parser 1409: // ${name.<[>code]}
1.206 paf 1410: push_LS(pc, LS_NAME_SQUARE_PART);
1.160 parser 1411: lexical_brackets_nestage=1;
1412: RC;
1.48 paf 1413: case '}': // ${name} finished, restoring LS
1.206 paf 1414: pop_LS(pc);
1.48 paf 1415: RC;
1416: case '.': // name part delim
1417: case '$': // name part subvar
1418: case ':': // ':name' or 'class:name'
1419: RC;
1.1 paf 1420: }
1421: break;
1.48 paf 1422:
1423: case LS_VAR_SQUARE:
1424: switch(c) {
1425: case '$':
1.206 paf 1426: push_LS(pc, LS_VAR_NAME_SIMPLE_WITH_COLON);
1.48 paf 1427: RC;
1428: case '^':
1.206 paf 1429: push_LS(pc, LS_METHOD_NAME);
1.48 paf 1430: RC;
1431: case ']':
1.1 paf 1432: if(--lexical_brackets_nestage==0) {
1.206 paf 1433: pop_LS(pc);
1.48 paf 1434: RC;
1.1 paf 1435: }
1.48 paf 1436: break;
1437: case ';': // operator_or_fmt;value delim
1438: RC;
1439: case '[':
1440: lexical_brackets_nestage++;
1441: break;
1.1 paf 1442: }
1443: break;
1.48 paf 1444:
1.1 paf 1445: case LS_VAR_CURLY:
1.48 paf 1446: switch(c) {
1447: case '$':
1.206 paf 1448: push_LS(pc, LS_VAR_NAME_SIMPLE_WITH_COLON);
1.48 paf 1449: RC;
1450: case '^':
1.206 paf 1451: push_LS(pc, LS_METHOD_NAME);
1.48 paf 1452: RC;
1453: case '}':
1.1 paf 1454: if(--lexical_brackets_nestage==0) {
1.206 paf 1455: pop_LS(pc);
1.48 paf 1456: RC;
1.1 paf 1457: }
1.48 paf 1458: break;
1459: case '{':
1.1 paf 1460: lexical_brackets_nestage++;
1.48 paf 1461: break;
1462: }
1.1 paf 1463: break;
1464:
1.10 paf 1465: // METHOD CALL
1.1 paf 1466: case LS_METHOD_NAME:
1.48 paf 1467: switch(c) {
1468: case '[':
1.166 parser 1469: // ^name.<[>code].xxx
1.206 paf 1470: if(pc.pos.col>1/*not first column*/ && (
1.163 parser 1471: end[-1]=='^'/*was start of call*/ || // never, ^[ is literal...
1472: end[-1]==':'/*was class name delim */ ||
1473: end[-1]=='.'/*was name delim */
1.162 parser 1474: )) {
1.206 paf 1475: push_LS(pc, LS_NAME_SQUARE_PART);
1.162 parser 1476: lexical_brackets_nestage=1;
1477: RC;
1478: }
1.206 paf 1479: pc.ls=LS_METHOD_SQUARE;
1.1 paf 1480: lexical_brackets_nestage=1;
1.48 paf 1481: RC;
1482: case '{':
1.206 paf 1483: pc.ls=LS_METHOD_CURLY;
1.1 paf 1484: lexical_brackets_nestage=1;
1.48 paf 1485: RC;
1.69 paf 1486: case '(':
1.206 paf 1487: pc.ls=LS_METHOD_ROUND;
1.69 paf 1488: lexical_brackets_nestage=1;
1489: RC;
1.48 paf 1490: case '.': // name part delim
1491: case '$': // name part subvar
1492: case ':': // ':name' or 'class:name'
1.170 parser 1493: case '^': // ^abc^xxx wrong. bailing out
1494: case ']': case '}': case ')': // ^abc]}) wrong. bailing out
1.207 paf 1495: case ' ': // ^if ( wrong. bailing out
1.48 paf 1496: RC;
1.1 paf 1497: }
1498: break;
1.48 paf 1499:
1500: case LS_METHOD_SQUARE:
1501: switch(c) {
1502: case '$':
1.206 paf 1503: push_LS(pc, LS_VAR_NAME_SIMPLE_WITH_COLON);
1.48 paf 1504: RC;
1505: case '^':
1.206 paf 1506: push_LS(pc, LS_METHOD_NAME);
1.48 paf 1507: RC;
1508: case ';': // param delim
1509: RC;
1510: case ']':
1.1 paf 1511: if(--lexical_brackets_nestage==0) {
1.206 paf 1512: pc.ls=LS_METHOD_AFTER;
1.48 paf 1513: RC;
1.1 paf 1514: }
1.48 paf 1515: break;
1516: case '[':
1.1 paf 1517: lexical_brackets_nestage++;
1.48 paf 1518: break;
1519: }
1.1 paf 1520: break;
1.48 paf 1521:
1.1 paf 1522: case LS_METHOD_CURLY:
1.48 paf 1523: switch(c) {
1524: case '$':
1.206 paf 1525: push_LS(pc, LS_VAR_NAME_SIMPLE_WITH_COLON);
1.48 paf 1526: RC;
1527: case '^':
1.206 paf 1528: push_LS(pc, LS_METHOD_NAME);
1.94 paf 1529: RC;
1530: case ';': // param delim
1.48 paf 1531: RC;
1532: case '}':
1.1 paf 1533: if(--lexical_brackets_nestage==0) {
1.206 paf 1534: pc.ls=LS_METHOD_AFTER;
1.48 paf 1535: RC;
1.1 paf 1536: }
1.48 paf 1537: break;
1538: case '{':
1.1 paf 1539: lexical_brackets_nestage++;
1.48 paf 1540: break;
1541: }
1.209 paf 1542: if(pc.explicit_result && c)
1543: switch(c) {
1544: case '\n': case ' ': case '\t':
1545: begin=pc.source;
1546: begin_pos=pc.pos;
1547: continue; // skip it
1548: default:
1549: result=BAD_NONWHITESPACE_CHARACTER_IN_EXPLICIT_RESULT_MODE;
1550: goto break2;
1551: }
1.1 paf 1552: break;
1.48 paf 1553:
1.1 paf 1554: case LS_METHOD_AFTER:
1.69 paf 1555: if(c=='[') {/* ][ }[ )[ */
1.206 paf 1556: pc.ls=LS_METHOD_SQUARE;
1.1 paf 1557: lexical_brackets_nestage=1;
1.48 paf 1558: RC;
1.1 paf 1559: }
1.69 paf 1560: if(c=='{') {/* ]{ }{ ){ */
1.206 paf 1561: pc.ls=LS_METHOD_CURLY;
1.69 paf 1562: lexical_brackets_nestage=1;
1563: RC;
1564: }
1565: if(c=='(') {/* ]( }( )( */
1.206 paf 1566: pc.ls=LS_METHOD_ROUND;
1.1 paf 1567: lexical_brackets_nestage=1;
1.48 paf 1568: RC;
1.1 paf 1569: }
1.206 paf 1570: pop_LS(pc);
1571: pc.ungetc();
1.13 paf 1572: result=EON;
1.1 paf 1573: goto break2;
1574: }
1.9 paf 1575: if(c==0) {
1.1 paf 1576: result=-1;
1577: break;
1578: }
1579: }
1580:
1581: break2:
1.59 paf 1582: if(end!=begin) { // there is last piece?
1583: if((c=='@' || c==0) && end[-1]=='\n') { // we are before LS_DEF_NAME or EOF?
1584: // strip last \n
1.10 paf 1585: end--;
1.137 parser 1586: if(end!=begin && end[-1]=='\n') // allow one empty line before LS_DEF_NAME
1587: end--;
1.59 paf 1588: }
1.206 paf 1589: if(end!=begin && pc.ls!=LS_USER_COMMENT) { // last piece still alive and not comment?
1590: if(!pc.string_start)
1591: pc.string_start=begin_pos;
1.59 paf 1592: // append it
1.206 paf 1593: pc.string.append_strdup_know_length(begin, end-begin);
1.30 paf 1594: }
1.59 paf 1595: }
1.206 paf 1596: if(!pc.string.is_empty()) { // something accumulated?
1597: // create STRING value: array of OP_VALUE+origin+vstring
1598: *lvalp=VL(
1599: new VString(*new String(pc.string, String::L_CLEAN)),
1600: pc.file_no, pc.string_start.line, pc.string_start.col);
1.10 paf 1601: // new pieces storage
1.206 paf 1602: pc.string.clear();
1603: pc.string_start.clear();
1.58 paf 1604: // make current result be pending for next call, return STRING for now
1.206 paf 1605: pc.pending_state=result; result=STRING;
1.58 paf 1606: }
1.67 paf 1607: if(skip_analized) {
1.206 paf 1608: pc.source+=skip_analized; pc.pos.col+=skip_analized;
1.1 paf 1609: }
1.58 paf 1610: return result;
1.1 paf 1611: }
1612:
1.206 paf 1613: static int real_yyerror(Parse_control *pc, char *s) { // Called by yyparse on error
1.114 paf 1614: strncpy(PC.error, s, MAX_STRING);
1.1 paf 1615: return 1;
1.110 paf 1616: }
1.1 paf 1617:
1.110 paf 1618: static void yyprint(FILE *file, int type, YYSTYPE value) {
1619: if(type==STRING)
1.206 paf 1620: fprintf(file, " \"%s\"", LA2S(*value)->cstr());
1.110 paf 1621: }
E-mail: