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