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