Annotation of parser3/src/main/compile.y, revision 1.248
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.248 ! misha 8: $Id: compile.y,v 1.247 2009-06-07 13:15:54 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.206 paf 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.206 paf 137: PC.cclass->add_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.231 misha 293: Method& method=*reinterpret_cast<Method*>($7);
294: // fill in the code
295: method.parser_code=$8;
296:
297: // register in class
298: const String& name=*LA2S(*$2);
299: PC.cclass->add_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 */
525: changetail_or_append(*$$,
526: OP::OP_CALL, true, /*=>*/ OP::OP_CALL__WRITE,
527: /*or */OP::OP_WRITE_VALUE); /* value=pop; wcontext.write(value) */
528: }
1.66 paf 529: };
1.177 paf 530: call_value: '^' {
1.180 paf 531: PC.in_call_value=true;
1.177 paf 532: }
533: call_name {
1.180 paf 534: PC.in_call_value=false;
1.177 paf 535: }
1.154 parser 536: store_params EON { /* ^field.$method{vasya} */
1.238 misha 537: #ifdef OPTIMIZE_BYTECODE_CUT_REM_OPERATOR
1.242 misha 538: #ifdef OPTIMIZE_BYTECODE_GET_ELEMENT
1.238 misha 539: const String* operator_name=LA2S(*$3, 0, OP::OP_VALUE__GET_ELEMENT_OR_OPERATOR);
1.242 misha 540: #else
541: const String* operator_name=LA2S(*$3, 1);
542: #endif
1.238 misha 543: if(operator_name && *operator_name == REM_OPERATOR_NAME){
544: $$=N();
545: } else
546: #endif
547: {
548: $$=$3; /* with_xxx,diving code; stack: context,method_junction */
1.123 paf 549:
1.238 misha 550: YYSTYPE params_code=$5;
551: if(params_code->count()==3) { // probably [] case. [OP::OP_VALUE+origin+Void]
552: if(Value* value=LA2V(*params_code)) // it is OP_VALUE+origin+value?
553: if(value->is_void()) // value is VVoid?
554: params_code=0; // ^zzz[] case. don't append lone empty param.
555: }
556: /* stack: context, method_junction */
557: OA(*$$, OP::OP_CALL, params_code); // method_frame=make frame(pop junction); ncontext=pop; call(ncontext,method_frame) stack: value
558: }
1.1 paf 559: };
560:
1.43 paf 561: call_name: name_without_curly_rdive;
1.38 paf 562:
1.206 paf 563: store_params: store_param | store_params store_param { $$=$1; P(*$$, *$2) };
1.69 paf 564: store_param:
565: store_square_param
566: | store_round_param
567: | store_curly_param
1.31 paf 568: ;
1.210 paf 569: store_square_param: '[' {
1.211 paf 570: // allow ^call[ letters here any time ]
1.210 paf 571: *reinterpret_cast<bool*>(&$$)=PC.explicit_result; PC.explicit_result=false;
572: } store_code_param_parts {
1.213 paf 573: PC.explicit_result=*reinterpret_cast<bool*>(&$2);
1.210 paf 574: } ']' {$$=$3};
1.69 paf 575: store_round_param: '(' store_expr_param_parts ')' {$$=$2};
1.94 paf 576: store_curly_param: '{' store_curly_param_parts '}' {$$=$2};
1.69 paf 577: store_code_param_parts:
578: store_code_param_part
1.206 paf 579: | store_code_param_parts ';' store_code_param_part { $$=$1; P(*$$, *$3) }
1.69 paf 580: ;
581: store_expr_param_parts:
582: store_expr_param_part
1.206 paf 583: | store_expr_param_parts ';' store_expr_param_part { $$=$1; P(*$$, *$3) }
1.69 paf 584: ;
1.94 paf 585: store_curly_param_parts:
586: store_curly_param_part
1.206 paf 587: | store_curly_param_parts ';' store_curly_param_part { $$=$1; P(*$$, *$3) }
1.94 paf 588: ;
1.120 paf 589: store_code_param_part: code_param_value {
1.32 paf 590: $$=$1;
1.120 paf 591: };
1.214 paf 592: store_expr_param_part: expr_value {
593: YYSTYPE expr_code=$1;
1.215 paf 594: if(expr_code->count()==3
1.234 misha 595: && (*expr_code)[0].code==OP::OP_VALUE) { // optimizing (double/bool/incidently 'string' too) case. [OP::OP_VALUE+origin+Double]. no evaluating
1.214 paf 596: $$=expr_code;
597: } else {
1.238 misha 598: YYSTYPE code=N();
1.229 misha 599: O(*code, OP::OP_PREPARE_TO_EXPRESSION);
1.214 paf 600: P(*code, *expr_code);
1.229 misha 601: O(*code, OP::OP_WRITE_EXPR_RESULT);
1.214 paf 602: $$=N();
1.229 misha 603: OA(*$$, OP::OP_EXPR_CODE__STORE_PARAM, code);
1.214 paf 604: }
1.69 paf 605: };
1.94 paf 606: store_curly_param_part: maybe_codes {
1.206 paf 607: $$=N();
1.229 misha 608: OA(*$$, OP::OP_CURLY_CODE__STORE_PARAM, $1);
1.94 paf 609: };
1.120 paf 610: code_param_value:
1.157 parser 611: void_value /* optimized [;...] case */
1.120 paf 612: | STRING /* optimized [STRING] case */
613: | constructor_code_value /* [something complex] */
614: ;
1.1 paf 615:
616: /* name */
617:
1.206 paf 618: name_expr_dive_code: name_expr_value | name_path name_expr_value { $$=$1; P(*$$, *$2) };
1.1 paf 619:
1.206 paf 620: name_path: name_step | name_path name_step { $$=$1; P(*$$, *$2) };
1.1 paf 621: name_step: name_advance1 '.';
622: name_advance1: name_expr_value {
1.177 paf 623: // we know that name_advance1 not called from ^xxx context
624: // so we'll not check for operator call possibility as we do in name_advance2
625:
1.1 paf 626: /* stack: context */
627: $$=$1; /* stack: context,name */
1.229 misha 628: O(*$$, OP::OP_GET_ELEMENT); /* name=pop; context=pop; stack: context.get_element(name) */
1.1 paf 629: };
630: name_advance2: name_expr_value {
631: /* stack: context */
632: $$=$1; /* stack: context,name */
1.229 misha 633: O(*$$, OP::OP_GET_ELEMENT); /* name=pop; context=pop; stack: context.get_element(name) */
1.1 paf 634: }
1.4 paf 635: | STRING BOGUS
1.1 paf 636: ;
637: name_expr_value:
1.4 paf 638: STRING /* subname_is_const */
1.1 paf 639: | name_expr_subvar_value /* $subname_is_var_value */
1.160 parser 640: | name_expr_with_subvar_value /* xxx$part_of_subname_is_var_value */
1.166 parser 641: | name_square_code_value /* [codes] */
1.1 paf 642: ;
643: name_expr_subvar_value: '$' subvar_ref_name_rdive {
644: $$=$2;
1.229 misha 645: O(*$$, OP::OP_GET_ELEMENT);
1.1 paf 646: };
1.4 paf 647: name_expr_with_subvar_value: STRING subvar_get_writes {
1.238 misha 648: YYSTYPE code;
1.183 paf 649: {
1.206 paf 650: change_string_literal_to_write_string_literal(*(code=$1));
651: P(*code, *$2);
1.183 paf 652: }
1.206 paf 653: $$=N();
1.229 misha 654: OA(*$$, OP::OP_STRING_POOL, code);
1.1 paf 655: };
1.212 paf 656: name_square_code_value: '[' {
657: // allow $result_or_other_variable[ letters here any time ]
658: *reinterpret_cast<bool*>(&$$)=PC.explicit_result; PC.explicit_result=false;
659: } codes {
1.213 paf 660: PC.explicit_result=*reinterpret_cast<bool*>(&$2);
1.212 paf 661: } ']' {
1.206 paf 662: $$=N();
1.229 misha 663: OA(*$$, OP::OP_OBJECT_POOL, $3); /* stack: empty write context */
1.183 paf 664: /* some code that writes to that context */
665: /* context=pop; stack: context.value() */
1.160 parser 666: };
1.154 parser 667: subvar_ref_name_rdive: STRING {
1.206 paf 668: $$=N();
1.229 misha 669: O(*$$, OP::OP_WITH_READ);
1.206 paf 670: P(*$$, *$1);
1.1 paf 671: };
1.206 paf 672: subvar_get_writes: subvar__get_write | subvar_get_writes subvar__get_write { $$=$1; P(*$$, *$2) };
1.1 paf 673: subvar__get_write: '$' subvar_ref_name_rdive {
674: $$=$2;
1.229 misha 675: O(*$$, OP::OP_GET_ELEMENT__WRITE);
1.42 paf 676: };
677:
1.154 parser 678: class_prefix:
679: class_static_prefix
680: | class_constructor_prefix
681: ;
1.155 parser 682: class_static_prefix: STRING ':' {
683: $$=$1; // stack: class name string
1.206 paf 684: if(*LA2S(*$$) == BASE_NAME) { // pseudo BASE class
685: if(VStateless_class* base=PC.cclass->base_class()) {
686: change_string_literal_value(*$$, base->name());
1.189 paf 687: } else {
688: strcpy(PC.error, "no base class declared");
689: YYERROR;
690: }
691: }
1.233 misha 692: #ifdef OPTIMIZE_BYTECODE_GET_CLASS
1.238 misha 693: // optimized OP_VALUE+origin+string+OP_GET_CLASS => OP_VALUE__GET_CLASS+origin+string
1.245 misha 694: maybe_change_first_opcode(*$$, OP::OP_VALUE, OP::OP_VALUE__GET_CLASS)
1.233 misha 695: #else
1.229 misha 696: O(*$$, OP::OP_GET_CLASS);
1.233 misha 697: #endif
1.155 parser 698: };
699: class_constructor_prefix: class_static_prefix ':' {
1.154 parser 700: $$=$1;
1.180 paf 701: if(!PC.in_call_value) {
1.154 parser 702: strcpy(PC.error, ":: not allowed here");
703: YYERROR;
704: }
1.229 misha 705: O(*$$, OP::OP_PREPARE_TO_CONSTRUCT_OBJECT);
1.1 paf 706: };
707:
1.53 paf 708:
1.56 paf 709: /* expr */
1.53 paf 710:
1.214 paf 711: expr_value: expr;
1.56 paf 712: expr:
1.214 paf 713: double_or_STRING
1.216 paf 714: | true_value
715: | false_value
1.64 paf 716: | get_value
1.66 paf 717: | call_value
1.216 paf 718: | '"' string_inside_quotes_value '"' { $$ = $2 }
719: | '\'' string_inside_quotes_value '\'' { $$ = $2 }
1.60 paf 720: | '(' expr ')' { $$ = $2; }
721: /* stack: operand // stack: @operand */
1.229 misha 722: | '-' expr %prec NUNARY { $$=$2; O(*$$, OP::OP_NEG) }
1.202 paf 723: | '+' expr %prec NUNARY { $$=$2 }
1.229 misha 724: | '~' expr { $$=$2; O(*$$, OP::OP_INV) }
725: | '!' expr { $$=$2; O(*$$, OP::OP_NOT) }
726: | "def" expr { $$=$2; O(*$$, OP::OP_DEF) }
727: | "in" expr { $$=$2; O(*$$, OP::OP_IN) }
728: | "-f" expr { $$=$2; O(*$$, OP::OP_FEXISTS) }
729: | "-d" expr { $$=$2; O(*$$, OP::OP_DEXISTS) }
1.60 paf 730: /* stack: a,b // stack: a@b */
1.229 misha 731: | expr '-' expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_SUB) }
732: | expr '+' expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_ADD) }
733: | expr '*' expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_MUL) }
734: | expr '/' expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_DIV) }
735: | expr '%' expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_MOD) }
736: | expr '\\' expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_INTDIV) }
737: | expr "<<" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_BIN_SL) }
738: | expr ">>" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_BIN_SR) }
739: | expr '&' expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_BIN_AND) }
740: | expr '|' expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_BIN_OR) }
741: | expr "!|" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_BIN_XOR) }
742: | expr "&&" expr { $$=$1; OA(*$$, OP::OP_NESTED_CODE, $3); O(*$$, OP::OP_LOG_AND) }
743: | expr "||" expr { $$=$1; OA(*$$, OP::OP_NESTED_CODE, $3); O(*$$, OP::OP_LOG_OR) }
744: | expr "!||" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_LOG_XOR) }
745: | expr '<' expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_NUM_LT) }
746: | expr '>' expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_NUM_GT) }
747: | expr "<=" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_NUM_LE) }
748: | expr ">=" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_NUM_GE) }
749: | expr "==" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_NUM_EQ) }
750: | expr "!=" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_NUM_NE) }
751: | expr "lt" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_STR_LT) }
752: | expr "gt" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_STR_GT) }
753: | expr "le" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_STR_LE) }
754: | expr "ge" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_STR_GE) }
755: | expr "eq" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_STR_EQ) }
756: | expr "ne" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_STR_NE) }
757: | expr "is" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_IS) }
1.56 paf 758: ;
1.214 paf 759:
760: double_or_STRING: STRING {
1.238 misha 761: // optimized OP_STRING => OP_VALUE for doubles
1.214 paf 762: maybe_change_string_literal_to_double_literal(*($$=$1));
763: };
1.55 paf 764:
1.65 paf 765: string_inside_quotes_value: maybe_codes {
1.238 misha 766: #ifdef OPTIMIZE_BYTECODE_STRING_POOL
767: // it brakes ^if(" 09 "){...}
768: YYSTYPE code=$1;
769: $$=N();
1.239 misha 770: if(code->count()==3 && maybe_change_first_opcode(*code, OP::OP_STRING__WRITE, OP::OP_VALUE)){
1.238 misha 771: // optimized OP_STRING__WRITE+origin+value => OP_VALUE+origin+value without starting OP_STRING_POOL
772: P(*$$, *code);
773: } else {
774: OA(*$$, OP::OP_STRING_POOL, code); /* stack: empty write context */
775: }
776: #else
1.206 paf 777: $$=N();
1.229 misha 778: OA(*$$, OP::OP_STRING_POOL, $1); /* stack: empty write context */
1.238 misha 779: #endif
1.183 paf 780: /* some code that writes to that context */
781: /* context=pop; stack: context.get_string() */
1.53 paf 782: };
1.1 paf 783:
1.27 paf 784: /* basics */
1.1 paf 785:
1.81 paf 786: write_string: STRING {
1.238 misha 787: // optimized OP_STRING+OP_WRITE_VALUE => OP_STRING__WRITE
1.209 paf 788: change_string_literal_to_write_string_literal(*($$=$1))
1.54 paf 789: };
790:
1.216 paf 791: void_value: /* empty */ { $$=VL(/*we know that we will not change it*/const_cast<VVoid*>(&vvoid), 0, 0, 0) }
792: true_value: "true" { $$ = VL(/*we know that we will not change it*/const_cast<VBool*>(&vtrue), 0, 0, 0) }
793: false_value: "false" { $$ = VL(/*we know that we will not change it*/const_cast<VBool*>(&vfalse), 0, 0, 0) }
794:
1.206 paf 795: empty: /* empty */ { $$=N() };
1.1 paf 796:
797: %%
1.105 paf 798: #endif
1.1 paf 799:
800: /*
801: 000$111(2222)00
802: 000$111{3333}00
1.9 paf 803: $,^: push,=0
1.1 paf 804: 1:( { break=pop
805: 2:( ) pop
806: 3:{ } pop
807:
808: 000^111(2222)4444{33333}4000
1.9 paf 809: $,^: push,=0
1.1 paf 810: 1:( { break=pop
811: 2:( )=4
812: 3:{ }=4
813: 4:[^({]=pop
814: */
815:
1.206 paf 816: inline void ungetc(Parse_control& pc, uint last_line_end_col) {
817: pc.source--;
818: if(pc.pos.col==0) {
819: --pc.pos.line; pc.pos.col=last_line_end_col;
820: } else
821: --pc.pos.col;
822:
823: }
824: static int yylex(YYSTYPE *lvalp, void *apc) {
825: register Parse_control& pc=*static_cast<Parse_control*>(apc);
826:
827: #define lexical_brackets_nestage pc.brackets_nestages[pc.ls_sp]
1.48 paf 828: #define RC {result=c; goto break2; }
1.1 paf 829:
1.206 paf 830: register int c;
831: int result;
1.1 paf 832:
1.206 paf 833: if(pc.pending_state) {
834: result=pc.pending_state;
835: pc.pending_state=0;
1.1 paf 836: return result;
837: }
838:
1.206 paf 839: const char *begin=pc.source;
840: Pos begin_pos=pc.pos;
1.91 paf 841: const char *end;
1.67 paf 842: int skip_analized=0;
1.50 paf 843: while(true) {
1.206 paf 844: c=*(end=(pc.source++));
845: // fprintf(stderr, "\nchar: %c %02X; nestage: %d, sp=%d", c, c, lexical_brackets_nestage, pc.sp);
1.1 paf 846:
1.208 paf 847: if(c=='\n')
1.206 paf 848: pc.pos_next_line();
1.208 paf 849: else
1.206 paf 850: pc.pos_next_c(c);
1.208 paf 851: // fprintf(stderr, "\nchar: %c file(%d:%d)", c, pc.pos.line, pc.pos.col);
1.73 paf 852:
1.208 paf 853: if(pc.pos.col==0+1 && c=='@') {
1.206 paf 854: if(pc.ls==LS_DEF_SPECIAL_BODY) {
1.175 paf 855: // @SPECIAL
856: // ...
857: // @<here =
1.206 paf 858: pop_LS(pc); // exiting from LS_DEF_SPECIAL_BODY state
1.175 paf 859: } // continuing checks
1.206 paf 860: if(pc.ls==LS_USER) {
861: push_LS(pc, LS_DEF_NAME);
1.171 parser 862: RC;
1.175 paf 863: } else // @ in first column inside some code [when could that be?]
1.171 parser 864: result=BAD_METHOD_DECL_START;
865: goto break2;
1.209 paf 866: }
867: if(c=='^') {
1.206 paf 868: if(pc.ls==LS_METHOD_AFTER) {
1.203 paf 869: // handle after-method situation
1.206 paf 870: pop_LS(pc);
1.203 paf 871: result=EON;
872: skip_analized=-1; // return to punctuation afterwards to assure it's literality
873: goto break2;
874: }
1.206 paf 875: switch(pc.ls) {
1.169 parser 876: case LS_EXPRESSION_VAR_NAME_WITH_COLON:
877: case LS_EXPRESSION_VAR_NAME_WITHOUT_COLON:
878: case LS_VAR_NAME_SIMPLE_WITH_COLON:
879: case LS_VAR_NAME_SIMPLE_WITHOUT_COLON:
880: case LS_VAR_NAME_CURLY:
881: case LS_METHOD_NAME:
1.194 paf 882: case LS_USER_COMMENT:
1.169 parser 883: case LS_DEF_COMMENT:
884: // no literals in names, please
885: break;
886: default:
1.206 paf 887: switch(*pc.source) {
1.165 parser 888: // ^escaping some punctuators
1.228 misha 889: case '^': case '$': case ';': case '@':
1.126 paf 890: case '(': case ')':
1.48 paf 891: case '[': case ']':
892: case '{': case '}':
1.172 parser 893: case '"': case ':':
1.40 paf 894: if(end!=begin) {
1.206 paf 895: if(!pc.string_start)
896: pc.string_start=begin_pos;
1.40 paf 897: // append piece till ^
1.206 paf 898: pc.string.append_strdup_know_length(begin, end-begin);
1.40 paf 899: }
1.63 paf 900: // reset piece 'begin' position & line
1.206 paf 901: begin=pc.source; // ->punctuation
902: begin_pos=pc.pos;
1.203 paf 903: // skip over _ after ^
1.206 paf 904: pc.source++; pc.pos.col++;
1.203 paf 905: // skip analysis = forced literal
906: continue;
1.114 paf 907:
908: // converting ^#HH into char(hex(HH))
909: case '#':
910: if(end!=begin) {
1.206 paf 911: if(!pc.string_start)
912: pc.string_start=begin_pos;
1.114 paf 913: // append piece till ^
1.206 paf 914: pc.string.append_strdup_know_length(begin, end-begin);
1.114 paf 915: }
916: // #HH ?
1.228 misha 917: if(pc.source[1] && isxdigit(pc.source[1]) && pc.source[2] && isxdigit(pc.source[2])) {
1.218 paf 918: char c=(char)(
1.206 paf 919: hex_value[(unsigned char)pc.source[1]]*0x10+
1.218 paf 920: hex_value[(unsigned char)pc.source[2]]);
1.206 paf 921: if(c==0) {
1.114 paf 922: result=BAD_HEX_LITERAL;
923: goto break2; // wrong hex value[no ^#00 chars allowed]: bail out
924: }
925: // append char(hex(HH))
1.206 paf 926: pc.string.append(c);
1.114 paf 927: // skip over ^#HH
1.206 paf 928: pc.source+=3;
929: pc.pos.col+=3;
1.114 paf 930: // reset piece 'begin' position & line
1.206 paf 931: begin=pc.source; // ->after ^#HH
932: begin_pos=pc.pos;
1.203 paf 933: // skip analysis = forced literal
1.114 paf 934: continue;
935: }
1.228 misha 936: // just escaped char
937: // reset piece 'begin' position & line
938: begin=pc.source;
939: begin_pos=pc.pos;
940: // skip over _ after ^
941: pc.source++; pc.pos.col++;
942: // skip analysis = forced literal
943: continue;
1.1 paf 944: }
1.169 parser 945: break;
1.203 paf 946: }
1.169 parser 947: }
1.113 paf 948: // #comment start skipping
1.206 paf 949: if(c=='#' && pc.pos.col==1) {
1.112 paf 950: if(end!=begin) {
1.206 paf 951: if(!pc.string_start)
952: pc.string_start=begin_pos;
1.112 paf 953: // append piece till #
1.206 paf 954: pc.string.append_strdup_know_length(begin, end-begin);
1.112 paf 955: }
956: // fall into COMMENT lexical state [wait for \n]
1.206 paf 957: push_LS(pc, LS_USER_COMMENT);
1.175 paf 958: continue;
1.112 paf 959: }
1.206 paf 960: switch(pc.ls) {
1.10 paf 961:
962: // USER'S = NOT OURS
1.1 paf 963: case LS_USER:
1.206 paf 964: case LS_NAME_SQUARE_PART: // name.[here].xxx
965: if(pc.trim_bof)
1.153 parser 966: switch(c) {
967: case '\n': case ' ': case '\t':
1.206 paf 968: begin=pc.source;
969: begin_pos=pc.pos;
1.152 parser 970: continue; // skip it
1.153 parser 971: default:
1.206 paf 972: pc.trim_bof=false;
1.152 parser 973: }
1.48 paf 974: switch(c) {
975: case '$':
1.206 paf 976: push_LS(pc, LS_VAR_NAME_SIMPLE_WITH_COLON);
1.48 paf 977: RC;
978: case '^':
1.206 paf 979: push_LS(pc, LS_METHOD_NAME);
1.48 paf 980: RC;
1.166 parser 981: case ']':
1.206 paf 982: if(pc.ls==LS_NAME_SQUARE_PART)
1.166 parser 983: if(--lexical_brackets_nestage==0) {// $name.[co<]?>de<]?>
1.206 paf 984: pop_LS(pc); // $name.[co<]>de<]!>
1.166 parser 985: RC;
986: }
1.160 parser 987: break;
1.166 parser 988: case '[': // $name.[co<[>de]
1.206 paf 989: if(pc.ls==LS_NAME_SQUARE_PART)
1.166 parser 990: lexical_brackets_nestage++;
1.161 parser 991: break;
1.112 paf 992: }
1.209 paf 993: if(pc.explicit_result && c)
994: switch(c) {
995: case '\n': case ' ': case '\t':
996: begin=pc.source;
997: begin_pos=pc.pos;
998: continue; // skip it
999: default:
1000: result=BAD_NONWHITESPACE_CHARACTER_IN_EXPLICIT_RESULT_MODE;
1001: goto break2;
1002: }
1.112 paf 1003: break;
1004:
1005: // #COMMENT
1.194 paf 1006: case LS_USER_COMMENT:
1.112 paf 1007: if(c=='\n') {
1008: // skip comment
1.206 paf 1009: begin=pc.source;
1010: begin_pos=pc.pos;
1.112 paf 1011:
1.206 paf 1012: pop_LS(pc);
1.112 paf 1013: continue;
1.1 paf 1014: }
1.48 paf 1015: break;
1016:
1017: // STRING IN EXPRESSION
1.145 parser 1018: case LS_EXPRESSION_STRING_QUOTED:
1019: case LS_EXPRESSION_STRING_APOSTROFED:
1.48 paf 1020: switch(c) {
1021: case '"':
1.145 parser 1022: case '\'':
1023: if(
1.206 paf 1024: pc.ls == LS_EXPRESSION_STRING_QUOTED && c=='"' ||
1025: pc.ls == LS_EXPRESSION_STRING_APOSTROFED && c=='\'') {
1026: pop_LS(pc); //"abc". | 'abc'.
1.145 parser 1027: RC;
1028: }
1029: break;
1.48 paf 1030: case '$':
1.206 paf 1031: push_LS(pc, LS_VAR_NAME_SIMPLE_WITH_COLON);
1.48 paf 1032: RC;
1033: case '^':
1.206 paf 1034: push_LS(pc, LS_METHOD_NAME);
1.48 paf 1035: RC;
1.10 paf 1036: }
1037: break;
1038:
1039: // METHOD DEFINITION
1040: case LS_DEF_NAME:
1.48 paf 1041: switch(c) {
1042: case '[':
1.206 paf 1043: pc.ls=LS_DEF_PARAMS;
1.48 paf 1044: RC;
1045: case '\n':
1.206 paf 1046: pc.ls=LS_DEF_SPECIAL_BODY;
1.48 paf 1047: RC;
1.10 paf 1048: }
1049: break;
1.48 paf 1050:
1.10 paf 1051: case LS_DEF_PARAMS:
1.48 paf 1052: switch(c) {
1.192 paf 1053: case '$': // common error
1.193 paf 1054: result=BAD_METHOD_PARAMETER_NAME_CHARACTER;
1055: goto break2;
1.48 paf 1056: case ';':
1057: RC;
1058: case ']':
1.206 paf 1059: pc.ls=*pc.source=='['?LS_DEF_LOCALS:LS_DEF_COMMENT;
1.48 paf 1060: RC;
1.49 paf 1061: case '\n': // wrong. bailing out
1.206 paf 1062: pop_LS(pc);
1.48 paf 1063: RC;
1.10 paf 1064: }
1065: break;
1.48 paf 1066:
1.10 paf 1067: case LS_DEF_LOCALS:
1.48 paf 1068: switch(c) {
1069: case '[':
1070: case ';':
1071: RC;
1072: case ']':
1.206 paf 1073: pc.ls=LS_DEF_COMMENT;
1.48 paf 1074: RC;
1075: case '\n': // wrong. bailing out
1.206 paf 1076: pop_LS(pc);
1.48 paf 1077: RC;
1.10 paf 1078: }
1079: break;
1.48 paf 1080:
1.10 paf 1081: case LS_DEF_COMMENT:
1082: if(c=='\n') {
1.206 paf 1083: pop_LS(pc);
1.48 paf 1084: RC;
1.37 paf 1085: }
1086: break;
1087:
1.48 paf 1088: case LS_DEF_SPECIAL_BODY:
1.175 paf 1089: if(c=='\n')
1.48 paf 1090: RC;
1091: break;
1092:
1093: // (EXPRESSION)
1.69 paf 1094: case LS_VAR_ROUND:
1095: case LS_METHOD_ROUND:
1.48 paf 1096: switch(c) {
1097: case ')':
1098: if(--lexical_brackets_nestage==0)
1.206 paf 1099: if(pc.ls==LS_METHOD_ROUND) // method round param ended
1100: pc.ls=LS_METHOD_AFTER; // look for method end
1101: else // pc.ls==LS_VAR_ROUND // variable constructor ended
1102: pop_LS(pc); // return to normal life
1.48 paf 1103: RC;
1.194 paf 1104: case '#': // comment start skipping
1105: if(end!=begin) {
1.206 paf 1106: if(!pc.string_start)
1107: pc.string_start=begin_pos;
1.194 paf 1108: // append piece till #
1.206 paf 1109: pc.string.append_strdup_know_length(begin, end-begin);
1.194 paf 1110: }
1111: // fall into COMMENT lexical state [wait for \n]
1.206 paf 1112: push_LS(pc, LS_EXPRESSION_COMMENT);
1.194 paf 1113: lexical_brackets_nestage=1;
1114: continue;
1.48 paf 1115: case '$':
1.206 paf 1116: push_LS(pc, LS_EXPRESSION_VAR_NAME_WITH_COLON);
1.48 paf 1117: RC;
1118: case '^':
1.206 paf 1119: push_LS(pc, LS_METHOD_NAME);
1.48 paf 1120: RC;
1121: case '(':
1122: lexical_brackets_nestage++;
1123: RC;
1.67 paf 1124: case '-':
1.206 paf 1125: switch(*pc.source) {
1.127 paf 1126: case 'f': // -f
1.67 paf 1127: skip_analized=1;
1128: result=FEXISTS;
1.127 paf 1129: goto break2;
1130: case 'd': // -d
1131: skip_analized=1;
1132: result=DEXISTS;
1133: goto break2;
1.191 paf 1134: default: // minus
1.67 paf 1135: result=c;
1.127 paf 1136: goto break2;
1137: }
1.67 paf 1138: goto break2;
1.173 paf 1139: case '+': case '*': case '/': case '%': case '\\':
1.58 paf 1140: case '~':
1.48 paf 1141: case ';':
1142: RC;
1.193 paf 1143: case '&': case '|':
1.206 paf 1144: if(*pc.source==c) { // && ||
1.193 paf 1145: result=c=='&'?LAND:LOR;
1.67 paf 1146: skip_analized=1;
1.58 paf 1147: } else
1148: result=c;
1149: goto break2;
1.193 paf 1150: case '!':
1.206 paf 1151: switch(pc.source[0]) {
1.193 paf 1152: case '|': // !| !||
1153: skip_analized=1;
1.206 paf 1154: if(pc.source[1]=='|') {
1.193 paf 1155: skip_analized++;
1156: result=LXOR;
1157: } else
1158: result=NXOR;
1159: goto break2;
1160: case '=': // !=
1161: skip_analized=1;
1162: result=NNE;
1163: goto break2;
1164: }
1165: RC;
1.195 paf 1166:
1167: case '<': // <<, <=, <
1.206 paf 1168: switch(*pc.source) {
1.195 paf 1169: case '<': // <[<]
1170: skip_analized=1; result=NSL; break;
1171: case '=': // <[=]
1172: skip_analized=1; result=NLE; break;
1173: default: // <[]
1174: result=c; break;
1175: }
1176: goto break2;
1177: case '>': // >>, >=, >
1.206 paf 1178: switch(*pc.source) {
1.195 paf 1179: case '>': // >[>]
1180: skip_analized=1; result=NSR; break;
1181: case '=': // >[=]
1182: skip_analized=1; result=NGE; break;
1183: default: // >[]
1184: result=c; break;
1185: }
1186: goto break2;
1187: case '=': // ==
1.206 paf 1188: switch(*pc.source) {
1.195 paf 1189: case '=': // =[=]
1190: skip_analized=1; result=NEQ; break;
1191: default: // =[]
1192: result=c; break; // not used now
1193: }
1.58 paf 1194: goto break2;
1.195 paf 1195:
1.48 paf 1196: case '"':
1.206 paf 1197: push_LS(pc, LS_EXPRESSION_STRING_QUOTED);
1.145 parser 1198: RC;
1199: case '\'':
1.206 paf 1200: push_LS(pc, LS_EXPRESSION_STRING_APOSTROFED);
1.48 paf 1201: RC;
1.50 paf 1202: case 'l': case 'g': case 'e': case 'n':
1.51 paf 1203: if(end==begin) // right after whitespace
1.206 paf 1204: if(isspace(pc.source[1])) {
1205: switch(*pc.source) {
1.117 paf 1206: // case '?': // ok [and bad cases, yacc would bark at them]
1207: case 't': // lt gt [et nt]
1208: result=c=='l'?SLT:c=='g'?SGT:BAD_STRING_COMPARISON_OPERATOR;
1209: skip_analized=1;
1210: goto break2;
1211: case 'e': // le ge ne [ee]
1212: result=c=='l'?SLE:c=='g'?SGE:c=='n'?SNE:BAD_STRING_COMPARISON_OPERATOR;
1213: skip_analized=1;
1214: goto break2;
1215: case 'q': // eq [lq gq nq]
1216: result=c=='e'?SEQ:BAD_STRING_COMPARISON_OPERATOR;
1217: skip_analized=1;
1218: goto break2;
1219: }
1.67 paf 1220: }
1221: break;
1222: case 'i':
1223: if(end==begin) // right after whitespace
1.206 paf 1224: if(isspace(pc.source[1])) {
1225: switch(pc.source[0]) {
1.117 paf 1226: case 'n': // in
1.95 paf 1227: skip_analized=1;
1228: result=IN;
1229: goto break2;
1.117 paf 1230: case 's': // is
1.95 paf 1231: skip_analized=1;
1232: result=IS;
1233: goto break2;
1234: }
1.67 paf 1235: }
1236: break;
1237: case 'd':
1238: if(end==begin) // right after whitespace
1.206 paf 1239: if(pc.source[0]=='e' && pc.source[1]=='f') { // def
1.225 misha 1240: switch(pc.source[2]){
1241: case ' ': case '\t': case '\n': case '"': case '\'': case '^': case '$': // non-quoted string without whitespace after 'def' is not allowed
1242: skip_analized=2;
1243: result=DEF;
1244: goto break2;
1245: }
1246: // error: incorrect char after 'def'
1.50 paf 1247: }
1.48 paf 1248: break;
1.216 paf 1249: case 't':
1250: if(end==begin) // right after whitespace
1.225 misha 1251: if(pc.source[0]=='r' && pc.source[1]=='u' && pc.source[2]=='e') { // true
1.216 paf 1252: skip_analized=3;
1253: result=LITERAL_TRUE;
1254: goto break2;
1255: }
1256: break;
1257: case 'f':
1258: if(end==begin) // right after whitespace
1.225 misha 1259: if(pc.source[0]=='a' && pc.source[1]=='l' && pc.source[2]=='s' && pc.source[3]=='e') { // false
1.216 paf 1260: skip_analized=4;
1261: result=LITERAL_FALSE;
1262: goto break2;
1263: }
1264: break;
1.48 paf 1265: case ' ': case '\t': case '\n':
1.63 paf 1266: if(end!=begin) { // there were a string after previous operator?
1267: result=0; // return that string
1268: goto break2;
1.48 paf 1269: }
1.63 paf 1270: // that's a leading|traling space or after-operator-space
1271: // ignoring it
1272: // reset piece 'begin' position & line
1.206 paf 1273: begin=pc.source; // after whitespace char
1274: begin_pos=pc.pos;
1.48 paf 1275: continue;
1.1 paf 1276: }
1277: break;
1.194 paf 1278: case LS_EXPRESSION_COMMENT:
1279: if(c=='(')
1280: lexical_brackets_nestage++;
1281:
1.206 paf 1282: switch(*pc.source) {
1.194 paf 1283: case '\n': case ')':
1.206 paf 1284: if(*pc.source==')')
1.194 paf 1285: if(--lexical_brackets_nestage!=0)
1286: continue;
1287:
1288: // skip comment
1.206 paf 1289: begin=pc.source;
1290: begin_pos=pc.pos;
1.194 paf 1291:
1.206 paf 1292: pop_LS(pc);
1.194 paf 1293: continue;
1294: }
1295: break;
1.1 paf 1296:
1.10 paf 1297: // VARIABLE GET/PUT/WITH
1.166 parser 1298: case LS_VAR_NAME_SIMPLE_WITH_COLON:
1299: case LS_VAR_NAME_SIMPLE_WITHOUT_COLON:
1300: case LS_EXPRESSION_VAR_NAME_WITH_COLON:
1301: case LS_EXPRESSION_VAR_NAME_WITHOUT_COLON:
1302: if(
1.206 paf 1303: pc.ls==LS_EXPRESSION_VAR_NAME_WITH_COLON ||
1304: pc.ls==LS_EXPRESSION_VAR_NAME_WITHOUT_COLON) {
1.181 paf 1305: // name in expr ends also before
1.48 paf 1306: switch(c) {
1.181 paf 1307: // expression minus
1.92 paf 1308: case '-':
1.181 paf 1309: // expression integer division
1310: case '\\':
1.206 paf 1311: pop_LS(pc);
1312: pc.ungetc();
1.48 paf 1313: result=EON;
1314: goto break2;
1315: }
1316: }
1.166 parser 1317: if(
1.206 paf 1318: pc.ls==LS_VAR_NAME_SIMPLE_WITHOUT_COLON ||
1319: pc.ls==LS_EXPRESSION_VAR_NAME_WITHOUT_COLON) {
1.142 parser 1320: // name already has ':', stop before next
1321: switch(c) {
1322: case ':':
1.206 paf 1323: pop_LS(pc);
1324: pc.ungetc();
1.142 parser 1325: result=EON;
1326: goto break2;
1327: }
1328: }
1.48 paf 1329: switch(c) {
1330: case 0:
1331: case ' ': case '\t': case '\n':
1332: case ';':
1.126 paf 1333: case ']': case '}': case ')':
1334: case '"': case '\'':
1.139 parser 1335: case '<': case '>': // these stand for HTML brackets AND expression binary ops
1.92 paf 1336: case '+': case '*': case '/': case '%':
1337: case '&': case '|':
1338: case '=': case '!':
1.99 paf 1339: // common delimiters
1.190 paf 1340: case ',': case '?': case '#':
1.220 paf 1341: // mysql column separators
1342: case '`':
1.139 parser 1343: // before call
1344: case '^':
1.206 paf 1345: pop_LS(pc);
1346: pc.ungetc();
1.13 paf 1347: result=EON;
1.1 paf 1348: goto break2;
1.48 paf 1349: case '[':
1.162 parser 1350: // $name.<[>code]
1.206 paf 1351: if(pc.pos.col>1/*not first column*/ && (
1.163 parser 1352: end[-1]=='$'/*was start of get*/ ||
1353: end[-1]==':'/*was class name delim */ ||
1354: end[-1]=='.'/*was name delim */
1.162 parser 1355: )) {
1.206 paf 1356: push_LS(pc, LS_NAME_SQUARE_PART);
1.162 parser 1357: lexical_brackets_nestage=1;
1358: RC;
1359: }
1.206 paf 1360: pc.ls=LS_VAR_SQUARE;
1.1 paf 1361: lexical_brackets_nestage=1;
1.48 paf 1362: RC;
1363: case '{':
1364: if(begin==end) { // ${name}, no need of EON, switching LS
1.206 paf 1365: pc.ls=LS_VAR_NAME_CURLY;
1.48 paf 1366: } else {
1.206 paf 1367: pc.ls=LS_VAR_CURLY;
1.48 paf 1368: lexical_brackets_nestage=1;
1369: }
1.69 paf 1370:
1.48 paf 1371: RC;
1372: case '(':
1.206 paf 1373: pc.ls=LS_VAR_ROUND;
1.1 paf 1374: lexical_brackets_nestage=1;
1.48 paf 1375: RC;
1376: case '.': // name part delim
1377: case '$': // name part subvar
1.160 parser 1378: case ':': // class<:>name
1.166 parser 1379: // go to _WITHOUT_COLON state variant...
1.206 paf 1380: if(pc.ls==LS_VAR_NAME_SIMPLE_WITH_COLON)
1381: pc.ls=LS_VAR_NAME_SIMPLE_WITHOUT_COLON;
1382: else if(pc.ls==LS_EXPRESSION_VAR_NAME_WITH_COLON)
1383: pc.ls=LS_EXPRESSION_VAR_NAME_WITHOUT_COLON;
1.166 parser 1384: // ...stop before next ':'
1.48 paf 1385: RC;
1.1 paf 1386: }
1387: break;
1.48 paf 1388:
1.1 paf 1389: case LS_VAR_NAME_CURLY:
1.48 paf 1390: switch(c) {
1.162 parser 1391: case '[':
1.166 parser 1392: // ${name.<[>code]}
1.206 paf 1393: push_LS(pc, LS_NAME_SQUARE_PART);
1.160 parser 1394: lexical_brackets_nestage=1;
1395: RC;
1.48 paf 1396: case '}': // ${name} finished, restoring LS
1.206 paf 1397: pop_LS(pc);
1.48 paf 1398: RC;
1399: case '.': // name part delim
1400: case '$': // name part subvar
1401: case ':': // ':name' or 'class:name'
1402: RC;
1.1 paf 1403: }
1404: break;
1.48 paf 1405:
1406: case LS_VAR_SQUARE:
1407: switch(c) {
1408: case '$':
1.206 paf 1409: push_LS(pc, LS_VAR_NAME_SIMPLE_WITH_COLON);
1.48 paf 1410: RC;
1411: case '^':
1.206 paf 1412: push_LS(pc, LS_METHOD_NAME);
1.48 paf 1413: RC;
1414: case ']':
1.1 paf 1415: if(--lexical_brackets_nestage==0) {
1.206 paf 1416: pop_LS(pc);
1.48 paf 1417: RC;
1.1 paf 1418: }
1.48 paf 1419: break;
1420: case ';': // operator_or_fmt;value delim
1421: RC;
1422: case '[':
1423: lexical_brackets_nestage++;
1424: break;
1.1 paf 1425: }
1426: break;
1.48 paf 1427:
1.1 paf 1428: case LS_VAR_CURLY:
1.48 paf 1429: switch(c) {
1430: case '$':
1.206 paf 1431: push_LS(pc, LS_VAR_NAME_SIMPLE_WITH_COLON);
1.48 paf 1432: RC;
1433: case '^':
1.206 paf 1434: push_LS(pc, LS_METHOD_NAME);
1.48 paf 1435: RC;
1436: case '}':
1.1 paf 1437: if(--lexical_brackets_nestage==0) {
1.206 paf 1438: pop_LS(pc);
1.48 paf 1439: RC;
1.1 paf 1440: }
1.48 paf 1441: break;
1442: case '{':
1.1 paf 1443: lexical_brackets_nestage++;
1.48 paf 1444: break;
1445: }
1.1 paf 1446: break;
1447:
1.10 paf 1448: // METHOD CALL
1.1 paf 1449: case LS_METHOD_NAME:
1.48 paf 1450: switch(c) {
1451: case '[':
1.166 parser 1452: // ^name.<[>code].xxx
1.206 paf 1453: if(pc.pos.col>1/*not first column*/ && (
1.163 parser 1454: end[-1]=='^'/*was start of call*/ || // never, ^[ is literal...
1455: end[-1]==':'/*was class name delim */ ||
1456: end[-1]=='.'/*was name delim */
1.162 parser 1457: )) {
1.206 paf 1458: push_LS(pc, LS_NAME_SQUARE_PART);
1.162 parser 1459: lexical_brackets_nestage=1;
1460: RC;
1461: }
1.206 paf 1462: pc.ls=LS_METHOD_SQUARE;
1.1 paf 1463: lexical_brackets_nestage=1;
1.48 paf 1464: RC;
1465: case '{':
1.206 paf 1466: pc.ls=LS_METHOD_CURLY;
1.1 paf 1467: lexical_brackets_nestage=1;
1.48 paf 1468: RC;
1.69 paf 1469: case '(':
1.206 paf 1470: pc.ls=LS_METHOD_ROUND;
1.69 paf 1471: lexical_brackets_nestage=1;
1472: RC;
1.48 paf 1473: case '.': // name part delim
1474: case '$': // name part subvar
1475: case ':': // ':name' or 'class:name'
1.170 parser 1476: case '^': // ^abc^xxx wrong. bailing out
1477: case ']': case '}': case ')': // ^abc]}) wrong. bailing out
1.207 paf 1478: case ' ': // ^if ( wrong. bailing out
1.48 paf 1479: RC;
1.1 paf 1480: }
1481: break;
1.48 paf 1482:
1483: case LS_METHOD_SQUARE:
1484: switch(c) {
1485: case '$':
1.206 paf 1486: push_LS(pc, LS_VAR_NAME_SIMPLE_WITH_COLON);
1.48 paf 1487: RC;
1488: case '^':
1.206 paf 1489: push_LS(pc, LS_METHOD_NAME);
1.48 paf 1490: RC;
1491: case ';': // param delim
1492: RC;
1493: case ']':
1.1 paf 1494: if(--lexical_brackets_nestage==0) {
1.206 paf 1495: pc.ls=LS_METHOD_AFTER;
1.48 paf 1496: RC;
1.1 paf 1497: }
1.48 paf 1498: break;
1499: case '[':
1.1 paf 1500: lexical_brackets_nestage++;
1.48 paf 1501: break;
1502: }
1.1 paf 1503: break;
1.48 paf 1504:
1.1 paf 1505: case LS_METHOD_CURLY:
1.48 paf 1506: switch(c) {
1507: case '$':
1.206 paf 1508: push_LS(pc, LS_VAR_NAME_SIMPLE_WITH_COLON);
1.48 paf 1509: RC;
1510: case '^':
1.206 paf 1511: push_LS(pc, LS_METHOD_NAME);
1.94 paf 1512: RC;
1513: case ';': // param delim
1.48 paf 1514: RC;
1515: case '}':
1.1 paf 1516: if(--lexical_brackets_nestage==0) {
1.206 paf 1517: pc.ls=LS_METHOD_AFTER;
1.48 paf 1518: RC;
1.1 paf 1519: }
1.48 paf 1520: break;
1521: case '{':
1.1 paf 1522: lexical_brackets_nestage++;
1.48 paf 1523: break;
1524: }
1.209 paf 1525: if(pc.explicit_result && c)
1526: switch(c) {
1527: case '\n': case ' ': case '\t':
1528: begin=pc.source;
1529: begin_pos=pc.pos;
1530: continue; // skip it
1531: default:
1532: result=BAD_NONWHITESPACE_CHARACTER_IN_EXPLICIT_RESULT_MODE;
1533: goto break2;
1534: }
1.1 paf 1535: break;
1.48 paf 1536:
1.1 paf 1537: case LS_METHOD_AFTER:
1.69 paf 1538: if(c=='[') {/* ][ }[ )[ */
1.206 paf 1539: pc.ls=LS_METHOD_SQUARE;
1.1 paf 1540: lexical_brackets_nestage=1;
1.48 paf 1541: RC;
1.1 paf 1542: }
1.69 paf 1543: if(c=='{') {/* ]{ }{ ){ */
1.206 paf 1544: pc.ls=LS_METHOD_CURLY;
1.69 paf 1545: lexical_brackets_nestage=1;
1546: RC;
1547: }
1548: if(c=='(') {/* ]( }( )( */
1.206 paf 1549: pc.ls=LS_METHOD_ROUND;
1.1 paf 1550: lexical_brackets_nestage=1;
1.48 paf 1551: RC;
1.1 paf 1552: }
1.206 paf 1553: pop_LS(pc);
1554: pc.ungetc();
1.13 paf 1555: result=EON;
1.1 paf 1556: goto break2;
1557: }
1.9 paf 1558: if(c==0) {
1.1 paf 1559: result=-1;
1560: break;
1561: }
1562: }
1563:
1564: break2:
1.59 paf 1565: if(end!=begin) { // there is last piece?
1566: if((c=='@' || c==0) && end[-1]=='\n') { // we are before LS_DEF_NAME or EOF?
1567: // strip last \n
1.10 paf 1568: end--;
1.137 parser 1569: if(end!=begin && end[-1]=='\n') // allow one empty line before LS_DEF_NAME
1570: end--;
1.59 paf 1571: }
1.206 paf 1572: if(end!=begin && pc.ls!=LS_USER_COMMENT) { // last piece still alive and not comment?
1573: if(!pc.string_start)
1574: pc.string_start=begin_pos;
1.59 paf 1575: // append it
1.206 paf 1576: pc.string.append_strdup_know_length(begin, end-begin);
1.30 paf 1577: }
1.59 paf 1578: }
1.206 paf 1579: if(!pc.string.is_empty()) { // something accumulated?
1580: // create STRING value: array of OP_VALUE+origin+vstring
1581: *lvalp=VL(
1582: new VString(*new String(pc.string, String::L_CLEAN)),
1583: pc.file_no, pc.string_start.line, pc.string_start.col);
1.10 paf 1584: // new pieces storage
1.206 paf 1585: pc.string.clear();
1586: pc.string_start.clear();
1.58 paf 1587: // make current result be pending for next call, return STRING for now
1.206 paf 1588: pc.pending_state=result; result=STRING;
1.58 paf 1589: }
1.67 paf 1590: if(skip_analized) {
1.206 paf 1591: pc.source+=skip_analized; pc.pos.col+=skip_analized;
1.1 paf 1592: }
1.58 paf 1593: return result;
1.1 paf 1594: }
1595:
1.206 paf 1596: static int real_yyerror(Parse_control *pc, char *s) { // Called by yyparse on error
1.114 paf 1597: strncpy(PC.error, s, MAX_STRING);
1.1 paf 1598: return 1;
1.110 paf 1599: }
1.1 paf 1600:
1.110 paf 1601: static void yyprint(FILE *file, int type, YYSTYPE value) {
1602: if(type==STRING)
1.206 paf 1603: fprintf(file, " \"%s\"", LA2S(*value)->cstr());
1.110 paf 1604: }
E-mail: