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