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