Annotation of parser3/src/main/compile.y, revision 1.163
1.105 paf 1: /** @file
1.106 paf 2: Parser: compiler(lexical parser and grammar).
3:
1.87 paf 4: Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.106 paf 5:
1.89 paf 6: Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
1.88 paf 7: */
1.144 parser 8: %{
1.163 ! parser 9: static char *RCSId="$Id: compile.y,v 1.162 2001/08/10 13:03:05 parser Exp $";
1.88 paf 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.90 paf 22: #define YYSTYPE Array/*<Operation>*/ *
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.9 paf 27: #define yyerror(msg) real_yyerror((parse_control *)pc, msg)
28: #define YYPRINT(file, type, value) yyprint(file, type, value)
1.1 paf 29:
30: #include "compile_tools.h"
1.8 paf 31: #include "pa_value.h"
1.12 paf 32: #include "pa_request.h"
1.39 paf 33: #include "pa_vobject.h"
1.52 paf 34: #include "pa_vdouble.h"
1.98 paf 35: #include "pa_globals.h"
1.141 parser 36: #include "pa_vvoid.h"
1.39 paf 37:
1.85 paf 38: #define SELF_ELEMENT_NAME "self"
1.97 paf 39: #define USE_CONTROL_METHOD_NAME "USE"
1.1 paf 40:
1.125 paf 41: static int real_yyerror(parse_control *pc, char *s);
1.9 paf 42: static void yyprint(FILE *file, int type, YYSTYPE value);
1.125 paf 43: static int yylex(YYSTYPE *lvalp, void *pc);
1.1 paf 44:
45:
1.8 paf 46: // local convinient inplace typecast & var
1.114 paf 47: #define PC (*(parse_control *)pc)
48: #define POOL (*PC.pool)
1.25 paf 49: #undef NEW
50: #define NEW new(POOL)
1.107 paf 51: #ifndef DOXYGEN
1.1 paf 52: %}
53:
54: %pure_parser
55:
1.13 paf 56: %token EON
1.4 paf 57: %token STRING
1.1 paf 58: %token BOGUS
1.55 paf 59:
1.58 paf 60: %token BAD_STRING_COMPARISON_OPERATOR
1.114 paf 61: %token BAD_HEX_LITERAL
1.58 paf 62:
1.59 paf 63: %token LAND "&&"
1.58 paf 64: %token LOR "||"
1.59 paf 65: %token LXOR "##"
1.58 paf 66:
67: %token NLE "<="
68: %token NGE ">="
69: %token NEQ "=="
70: %token NNE "!="
71:
72: %token SLT "lt"
73: %token SGT "gt"
74: %token SLE "le"
75: %token SGE "ge"
76: %token SEQ "eq"
77: %token SNE "ne"
78:
1.67 paf 79: %token DEF "def"
80: %token IN "in"
81: %token FEXISTS "-f"
1.127 paf 82: %token DEXISTS "-d"
1.95 paf 83: %token IS "is"
1.67 paf 84:
1.57 paf 85: /* logical */
1.131 paf 86: %left "##"
1.57 paf 87: %left "||"
88: %left "&&"
1.131 paf 89: %left '<' '>' "<=" ">=" "lt" "gt" "le" "ge"
90: %left "==" "!=" "eq" "ne"
91: %left "is" "def" "in" "-f" "-d"
1.68 paf 92: %left '!'
1.57 paf 93:
94: /* bitwise */
1.59 paf 95: %left '#'
1.131 paf 96: %left '|'
97: %left '&'
1.68 paf 98: %left '~'
1.57 paf 99:
1.56 paf 100: /* numerical */
1.55 paf 101: %left '-' '+'
1.57 paf 102: %left '*' '/' '%'
1.56 paf 103: %left NEG /* negation: unary - */
1.1 paf 104:
105: %%
1.152 parser 106: all:
1.10 paf 107: one_big_piece {
1.75 paf 108: Method& method=*NEW Method(POOL,
1.85 paf 109: *main_method_name,
1.122 paf 110: Method::CT_ANY,
1.81 paf 111: 0, 0, /*min, max numbered_params_count*/
1.75 paf 112: 0/*param_names*/, 0/*local_names*/,
113: $1/*parser_code*/, 0/*native_code*/);
1.114 paf 114: PC.cclass->add_method(*main_method_name, method);
1.10 paf 115: }
116: | methods;
117:
118: methods: method | methods method;
119: one_big_piece: maybe_codes;
120:
1.34 paf 121: method: control_method | code_method;
122:
123: control_method: '@' STRING '\n'
1.132 paf 124: maybe_control_strings {
1.120 paf 125: const String& command=*LA2S($2);
1.34 paf 126: YYSTYPE strings_code=$4;
1.37 paf 127: if(strings_code->size()<1*2) {
1.114 paf 128: strcpy(PC.error, "@");
129: strcat(PC.error, command.cstr());
130: strcat(PC.error, " is empty");
1.37 paf 131: YYERROR;
132: }
1.74 paf 133: if(command==CLASS_NAME) {
1.146 parser 134: if(PC.cclass->base()) { // already changed from default?
1.114 paf 135: strcpy(PC.error, "class already have a name '");
136: strncat(PC.error, PC.cclass->name().cstr(), 100);
137: strcat(PC.error, "'");
1.73 paf 138: YYERROR;
139: }
140: if(strings_code->size()==1*2) {
141: // new class' name
1.120 paf 142: const String *name=LA2S(strings_code);
1.73 paf 143: // creating the class
1.114 paf 144: PC.cclass=NEW VClass(POOL);
145: PC.cclass->set_name(*name);
1.73 paf 146: // append to request's classes
1.114 paf 147: PC.request->classes().put(*name, PC.cclass);
1.73 paf 148: } else {
1.114 paf 149: strcpy(PC.error, "@"CLASS_NAME" must contain sole name");
1.34 paf 150: YYERROR;
151: }
1.130 paf 152: } else if(command==USE_CONTROL_METHOD_NAME) {
153: for(int i=0; i<strings_code->size(); i+=2)
1.159 parser 154: PC.request->use_file(*LA2S(strings_code, i));
1.130 paf 155: } else if(command==BASE_NAME) {
1.146 parser 156: if(PC.cclass->base()) { // already changed from default?
1.130 paf 157: strcpy(PC.error, "class already have a base '");
158: strncat(PC.error, PC.cclass->base()->name().cstr(), 100);
159: strcat(PC.error, "'");
160: YYERROR;
161: }
162: if(strings_code->size()==1*2) {
163: const String& base_name=*LA2S(strings_code);
164: VClass *base=static_cast<VClass *>(
165: PC.request->classes().get(base_name));
166: if(!base) {
167: strcpy(PC.error, base_name.cstr());
168: strcat(PC.error, ": undefined class in @"BASE_NAME);
1.73 paf 169: YYERROR;
170: }
1.130 paf 171: // @CLASS == @BASE sanity check
172: if(PC.cclass==base) {
173: strcpy(PC.error, "@"CLASS_NAME" equals @"BASE_NAME);
1.45 paf 174: YYERROR;
1.34 paf 175: }
1.130 paf 176: PC.cclass->set_base(*base);
1.34 paf 177: } else {
1.130 paf 178: strcpy(PC.error, "@"BASE_NAME" must contain sole name");
1.34 paf 179: YYERROR;
180: }
1.130 paf 181: } else {
182: strcpy(PC.error, "'");
183: strncat(PC.error, command.cstr(), MAX_STRING/2);
184: strcat(PC.error, "' invalid special name. valid names are "
185: "'"CLASS_NAME"', '"USE_CONTROL_METHOD_NAME"' and '"BASE_NAME"'");
186: YYERROR;
1.34 paf 187: }
188: };
1.132 paf 189: maybe_control_strings: empty | control_strings;
1.37 paf 190: control_strings: control_string | control_strings control_string { $$=$1; P($$, $2) };
191: control_string: maybe_string '\n';
192: maybe_string: empty | STRING;
1.34 paf 193:
194: code_method: '@' STRING bracketed_maybe_strings maybe_bracketed_strings maybe_comment '\n'
1.10 paf 195: maybe_codes {
1.120 paf 196: const String *name=LA2S($2);
1.10 paf 197:
198: YYSTYPE params_names_code=$3;
1.75 paf 199: Array *params_names=0;
200: if(int size=params_names_code->size()) {
201: params_names=NEW Array(POOL);
202: for(int i=0; i<size; i+=2)
1.120 paf 203: *params_names+=LA2S(params_names_code, i);
1.75 paf 204: }
1.10 paf 205:
206: YYSTYPE locals_names_code=$4;
1.75 paf 207: Array *locals_names=0;
208: if(int size=locals_names_code->size()) {
209: locals_names=NEW Array(POOL);
210: for(int i=0; i<size; i+=2)
1.120 paf 211: *locals_names+=LA2S(locals_names_code, i);
1.75 paf 212: }
1.10 paf 213:
1.76 paf 214: Method& method=*NEW Method(POOL,
215: *name,
1.122 paf 216: Method::CT_ANY,
1.81 paf 217: 0, 0/*min,max numbered_params_count*/,
1.76 paf 218: params_names, locals_names,
219: $7, 0);
1.114 paf 220: PC.cclass->add_method(*name, method);
1.8 paf 221: };
1.10 paf 222:
223: maybe_bracketed_strings: empty | bracketed_maybe_strings;
224: bracketed_maybe_strings: '[' maybe_strings ']' {$$=$2};
225: maybe_strings: empty | strings;
226: strings: STRING | strings ';' STRING { $$=$1; P($$, $3) };
227:
228: maybe_comment: empty | STRING;
1.1 paf 229:
230: /* codes */
231:
1.10 paf 232: maybe_codes: empty | codes;
233:
1.90 paf 234: codes: code | codes code { $$=$1; P($$, $2) };
1.81 paf 235: code: write_string | action;
1.149 parser 236: action: get | put | call;
1.1 paf 237:
238: /* get */
239:
1.64 paf 240: get: get_value {
241: $$=$1; /* stack: resulting value */
1.102 paf 242: O($$, OP_WRITE_VALUE); /* value=pop; wcontext.write(value) */
1.1 paf 243: };
1.163 ! parser 244: get_value: '$' get_name_value { $$=$2 };
1.64 paf 245: get_name_value: name_without_curly_rdive EON | name_in_curly_rdive;
1.1 paf 246: name_in_curly_rdive: '{' name_without_curly_rdive '}' { $$=$2 };
1.44 paf 247: name_without_curly_rdive:
248: name_without_curly_rdive_read
249: | name_without_curly_rdive_class;
1.19 paf 250: name_without_curly_rdive_read: name_without_curly_rdive_code {
1.25 paf 251: $$=N(POOL);
1.22 paf 252: Array *diving_code=$1;
1.120 paf 253: const String *first_name=LA2S(diving_code);
1.85 paf 254: if(first_name && *first_name==SELF_ELEMENT_NAME) {
1.54 paf 255: O($$, OP_WITH_SELF); /* stack: starting context */
1.22 paf 256: P($$, diving_code,
257: /* skip over... */
258: diving_code->size()>2?3/*OP_+string+get_element*/:2/*OP_+string*/);
259: } else {
1.54 paf 260: O($$, OP_WITH_READ); /* stack: starting context */
1.22 paf 261: P($$, diving_code);
262: }
263: /* diving code; stack: current context */
1.1 paf 264: };
1.155 parser 265: name_without_curly_rdive_class: class_prefix name_without_curly_rdive_code { $$=$1; P($$, $2) };
1.19 paf 266: name_without_curly_rdive_code: name_advance2 | name_path name_advance2 { $$=$1; P($$, $2) };
1.1 paf 267:
268: /* put */
269:
1.81 paf 270: put: '$' name_expr_wdive construct {
1.20 paf 271: $$=$2; /* stack: context,name */
1.52 paf 272: P($$, $3); /* stack: context,name,constructor_value */
1.20 paf 273: };
1.44 paf 274: name_expr_wdive:
1.157 parser 275: name_expr_wdive_root
276: | name_expr_wdive_write
1.44 paf 277: | name_expr_wdive_class;
1.157 parser 278: name_expr_wdive_root: name_expr_dive_code {
1.44 paf 279: $$=N(POOL);
1.23 paf 280: Array *diving_code=$1;
1.120 paf 281: const String *first_name=LA2S(diving_code);
1.85 paf 282: if(first_name && *first_name==SELF_ELEMENT_NAME) {
1.54 paf 283: O($$, OP_WITH_SELF); /* stack: starting context */
1.23 paf 284: P($$, diving_code,
285: /* skip over... */
286: diving_code->size()>2?3/*OP_+string+get_element*/:2/*OP_+string*/);
287: } else {
1.157 parser 288: O($$, OP_WITH_ROOT); /* stack: starting context */
1.23 paf 289: P($$, diving_code);
290: }
291: /* diving code; stack: current context */
1.156 parser 292: };
1.157 parser 293: name_expr_wdive_write: '.' name_expr_dive_code {
1.156 parser 294: $$=N(POOL);
1.157 parser 295: O($$, OP_WITH_WRITE); /* stack: starting context */
1.156 parser 296: P($$, $2); /* diving code; stack: context,name */
1.20 paf 297: };
1.155 parser 298: name_expr_wdive_class: class_prefix name_expr_dive_code { $$=$1; P($$, $2) };
1.20 paf 299:
1.149 parser 300: construct:
1.163 ! parser 301: construct_square
! 302: | construct_round
! 303: | construct_curly
1.149 parser 304: ;
305: construct_square: '[' any_constructor_code_value ']' {
306: // stack: context, name
307: $$=$2; // stack: context, name, value
1.81 paf 308: O($$, OP_CONSTRUCT_VALUE); /* value=pop; name=pop; context=pop; construct(context,name,value) */
309: }
310: ;
1.149 parser 311: construct_round: '(' expr_value ')' {
312: // stack: context, name
313: $$=$2; // stack: context, name, value
1.163 ! parser 314: O($$, OP_CONSTRUCT_EXPR); /* value=pop->as_expr_result; name=pop; context=pop; construct(context,name,value) */
1.81 paf 315: }
1.52 paf 316: ;
1.149 parser 317: construct_curly: '{' maybe_codes '}' {
318: // stack: context, name
319: $$=N(POOL);
320: CCA($$, $2); /* code=pop; name=pop; context=pop; construct(context,name,junction(code)) */
321: };
322:
1.55 paf 323: any_constructor_code_value:
1.157 parser 324: void_value /* optimized $var[] case */
1.52 paf 325: | STRING /* optimized $var[STRING] case */
1.55 paf 326: | constructor_code_value /* $var[something complex] */
1.1 paf 327: ;
1.55 paf 328: constructor_code_value: constructor_code {
1.25 paf 329: $$=N(POOL);
1.54 paf 330: O($$, OP_CREATE_EWPOOL); /* stack: empty write context */
1.69 paf 331: P($$, $1); /* some code that writes to that context */
1.54 paf 332: O($$, OP_REDUCE_EWPOOL); /* context=pop; stack: context.value() */
1.1 paf 333: };
1.55 paf 334: constructor_code: codes__excluding_sole_str_literal;
1.27 paf 335: codes__excluding_sole_str_literal: action | code codes { $$=$1; P($$, $2) };
336:
1.1 paf 337: /* call */
338:
1.66 paf 339: call: call_value {
340: $$=$1; /* stack: value */
1.102 paf 341: O($$, OP_WRITE_VALUE); /* value=pop; wcontext.write(value) */
1.66 paf 342: };
1.154 parser 343: call_value: '^' { PC.object_constructor_allowed=true }
344: call_name { PC.object_constructor_allowed=false }
345: store_params EON { /* ^field.$method{vasya} */
346: $$=$3; /* with_xxx,diving code; stack: context,method_junction */
1.54 paf 347: O($$, OP_GET_METHOD_FRAME); /* stack: context,method_frame */
1.123 paf 348:
1.154 parser 349: YYSTYPE params_code=$5;
1.140 parser 350: if(params_code->size()==3) // probably [] case. [OP_VALUE + Void + STORE_PARAM]
1.123 paf 351: if(Value *value=LA2V(params_code)) // it is OP_VALUE + value?
1.140 parser 352: if(!value->is_defined()) // value is VVoid?
1.123 paf 353: params_code=0; // ^zzz[] case. don't append lone empty param.
354: if(params_code)
355: P($$, params_code); // filling method_frame.store_params
1.155 parser 356: O($$, OP_CALL); // method_frame=pop; ncontext=pop; call(ncontext,method_frame) stack: value
1.1 paf 357: };
358:
1.43 paf 359: call_name: name_without_curly_rdive;
1.38 paf 360:
1.9 paf 361: store_params: store_param | store_params store_param { $$=$1; P($$, $2) };
1.69 paf 362: store_param:
363: store_square_param
364: | store_round_param
365: | store_curly_param
1.31 paf 366: ;
1.123 paf 367: store_square_param: '[' store_code_param_parts ']' {$$=$2};
1.69 paf 368: store_round_param: '(' store_expr_param_parts ')' {$$=$2};
1.94 paf 369: store_curly_param: '{' store_curly_param_parts '}' {$$=$2};
1.69 paf 370: store_code_param_parts:
371: store_code_param_part
372: | store_code_param_parts ';' store_code_param_part { $$=$1; P($$, $3) }
373: ;
374: store_expr_param_parts:
375: store_expr_param_part
376: | store_expr_param_parts ';' store_expr_param_part { $$=$1; P($$, $3) }
377: ;
1.94 paf 378: store_curly_param_parts:
379: store_curly_param_part
380: | store_curly_param_parts ';' store_curly_param_part { $$=$1; P($$, $3) }
381: ;
1.120 paf 382: store_code_param_part: code_param_value {
1.32 paf 383: $$=$1;
1.54 paf 384: O($$, OP_STORE_PARAM);
1.120 paf 385: };
1.69 paf 386: store_expr_param_part: write_expr_value {
387: $$=N(POOL);
1.103 paf 388: PEA($$, $1);
1.69 paf 389: };
1.94 paf 390: store_curly_param_part: maybe_codes {
391: $$=N(POOL);
392: PCA($$, $1);
393: };
1.120 paf 394: code_param_value:
1.157 parser 395: void_value /* optimized [;...] case */
1.120 paf 396: | STRING /* optimized [STRING] case */
397: | constructor_code_value /* [something complex] */
398: ;
1.90 paf 399: write_expr_value: expr_value {
1.69 paf 400: $$=$1;
1.102 paf 401: O($$, OP_WRITE_EXPR_RESULT);
1.69 paf 402: };
1.1 paf 403:
404: /* name */
405:
1.20 paf 406: name_expr_dive_code: name_expr_value | name_path name_expr_value { $$=$1; P($$, $2) };
1.1 paf 407:
1.9 paf 408: name_path: name_step | name_path name_step { $$=$1; P($$, $2) };
1.1 paf 409: name_step: name_advance1 '.';
410: name_advance1: name_expr_value {
411: /* stack: context */
412: $$=$1; /* stack: context,name */
1.54 paf 413: O($$, OP_GET_ELEMENT); /* name=pop; context=pop; stack: context.get_element(name) */
1.1 paf 414: };
415: name_advance2: name_expr_value {
416: /* stack: context */
417: $$=$1; /* stack: context,name */
1.54 paf 418: O($$, OP_GET_ELEMENT); /* name=pop; context=pop; stack: context.get_element(name) */
1.1 paf 419: }
1.4 paf 420: | STRING BOGUS
1.1 paf 421: ;
422: name_expr_value:
1.4 paf 423: STRING /* subname_is_const */
1.1 paf 424: | name_expr_subvar_value /* $subname_is_var_value */
1.160 parser 425: | name_expr_with_subvar_value /* xxx$part_of_subname_is_var_value */
426: | name_curly_code_value /* (codes) */
1.1 paf 427: ;
428: name_expr_subvar_value: '$' subvar_ref_name_rdive {
429: $$=$2;
1.54 paf 430: O($$, OP_GET_ELEMENT);
1.1 paf 431: };
1.4 paf 432: name_expr_with_subvar_value: STRING subvar_get_writes {
1.25 paf 433: $$=N(POOL);
1.54 paf 434: O($$, OP_CREATE_EWPOOL);
1.9 paf 435: P($$, $1);
1.102 paf 436: O($$, OP_WRITE_VALUE);
1.9 paf 437: P($$, $2);
1.54 paf 438: O($$, OP_REDUCE_EWPOOL);
1.1 paf 439: };
1.162 parser 440: name_curly_code_value: '[' codes ']' {
1.160 parser 441: $$=N(POOL);
442: O($$, OP_CREATE_EWPOOL);
443: P($$, $2);
444: O($$, OP_REDUCE_EWPOOL);
445: };
1.154 parser 446: subvar_ref_name_rdive: STRING {
1.25 paf 447: $$=N(POOL);
1.54 paf 448: O($$, OP_WITH_READ);
1.9 paf 449: P($$, $1);
1.1 paf 450: };
1.9 paf 451: subvar_get_writes: subvar__get_write | subvar_get_writes subvar__get_write { $$=$1; P($$, $2) };
1.1 paf 452: subvar__get_write: '$' subvar_ref_name_rdive {
453: $$=$2;
1.54 paf 454: O($$, OP_GET_ELEMENT__WRITE);
1.42 paf 455: };
456:
1.154 parser 457: class_prefix:
458: class_static_prefix
459: | class_constructor_prefix
460: ;
1.155 parser 461: class_static_prefix: STRING ':' {
462: $$=$1; // stack: class name string
463: O($$, OP_GET_CLASS);
464: };
465: class_constructor_prefix: class_static_prefix ':' {
1.154 parser 466: $$=$1;
467: if(!PC.object_constructor_allowed) {
468: strcpy(PC.error, ":: not allowed here");
469: YYERROR;
470: }
1.155 parser 471: O($$, OP_PREPARE_TO_CONSTRUCT_OBJECT);
1.1 paf 472: };
473:
1.53 paf 474:
1.56 paf 475: /* expr */
1.53 paf 476:
1.81 paf 477: expr_value: expr {
478: if(($$=$1)->size()==2) // only one string literal in there?
1.62 paf 479: change_string_literal_to_double_literal($$); // make that string literal Double
480: };
1.56 paf 481: expr:
1.62 paf 482: STRING
1.64 paf 483: | get_value
1.66 paf 484: | call_value
1.64 paf 485: | '"' string_inside_quotes_value '"' { $$ = $2; }
1.145 parser 486: | '\'' string_inside_quotes_value '\'' { $$ = $2; }
1.60 paf 487: | '(' expr ')' { $$ = $2; }
488: /* stack: operand // stack: @operand */
489: | '-' expr %prec NEG { $$=$2; O($$, OP_NEG) }
1.68 paf 490: | '~' expr { $$=$2; O($$, OP_INV) }
491: | '!' expr { $$=$2; O($$, OP_NOT) }
492: | "def" expr { $$=$2; O($$, OP_DEF) }
493: | "in" expr { $$=$2; O($$, OP_IN) }
494: | "-f" expr { $$=$2; O($$, OP_FEXISTS) }
1.127 paf 495: | "-d" expr { $$=$2; O($$, OP_DEXISTS) }
1.60 paf 496: /* stack: a,b // stack: a@b */
497: | expr '-' expr { $$=$1; P($$, $3); O($$, OP_SUB) }
498: | expr '+' expr { $$=$1; P($$, $3); O($$, OP_ADD) }
499: | expr '*' expr { $$=$1; P($$, $3); O($$, OP_MUL) }
500: | expr '/' expr { $$=$1; P($$, $3); O($$, OP_DIV) }
501: | expr '%' expr { $$=$1; P($$, $3); O($$, OP_MOD) }
502: | expr '&' expr { $$=$1; P($$, $3); O($$, OP_BIN_AND) }
503: | expr '|' expr { $$=$1; P($$, $3); O($$, OP_BIN_OR) }
504: | expr '#' expr { $$=$1; P($$, $3); O($$, OP_BIN_XOR) }
505: | expr "&&" expr { $$=$1; P($$, $3); O($$, OP_LOG_AND) }
506: | expr "||" expr { $$=$1; P($$, $3); O($$, OP_LOG_OR) }
507: | expr "##" expr { $$=$1; P($$, $3); O($$, OP_LOG_XOR) }
508: | expr '<' expr { $$=$1; P($$, $3); O($$, OP_NUM_LT) }
509: | expr '>' expr { $$=$1; P($$, $3); O($$, OP_NUM_GT) }
510: | expr "<=" expr { $$=$1; P($$, $3); O($$, OP_NUM_LE) }
511: | expr ">=" expr { $$=$1; P($$, $3); O($$, OP_NUM_GE) }
512: | expr "==" expr { $$=$1; P($$, $3); O($$, OP_NUM_EQ) }
513: | expr "!=" expr { $$=$1; P($$, $3); O($$, OP_NUM_NE) }
1.61 paf 514: | expr "lt" expr { $$=$1; P($$, $3); O($$, OP_STR_LT) }
515: | expr "gt" expr { $$=$1; P($$, $3); O($$, OP_STR_GT) }
516: | expr "le" expr { $$=$1; P($$, $3); O($$, OP_STR_LE) }
517: | expr "ge" expr { $$=$1; P($$, $3); O($$, OP_STR_GE) }
518: | expr "eq" expr { $$=$1; P($$, $3); O($$, OP_STR_EQ) }
519: | expr "ne" expr { $$=$1; P($$, $3); O($$, OP_STR_NE) }
1.95 paf 520: | expr "is" expr { $$=$1; P($$, $3); O($$, OP_IS) }
1.56 paf 521: ;
1.55 paf 522:
1.65 paf 523: string_inside_quotes_value: maybe_codes {
1.64 paf 524: $$=N(POOL);
525: O($$, OP_CREATE_SWPOOL); /* stack: empty write context */
1.69 paf 526: P($$, $1); /* some code that writes to that context */
1.64 paf 527: O($$, OP_REDUCE_SWPOOL); /* context=pop; stack: context.get_string() */
1.53 paf 528: };
1.1 paf 529:
1.27 paf 530: /* basics */
1.1 paf 531:
1.81 paf 532: write_string: STRING {
1.102 paf 533: // optimized from OP_STRING+OP_WRITE_VALUE to OP_STRING__WRITE
1.84 paf 534: change_string_literal_to_write_string_literal($$=$1)
1.54 paf 535: };
536:
1.157 parser 537: void_value: /* empty */ { $$=VL(NEW VVoid(POOL)) };
1.25 paf 538: empty: /* empty */ { $$=N(POOL) };
1.1 paf 539:
540: %%
1.105 paf 541: #endif
1.1 paf 542:
543: /*
544: 000$111(2222)00
545: 000$111{3333}00
1.9 paf 546: $,^: push,=0
1.1 paf 547: 1:( { break=pop
548: 2:( ) pop
549: 3:{ } pop
550:
551: 000^111(2222)4444{33333}4000
1.9 paf 552: $,^: push,=0
1.1 paf 553: 1:( { break=pop
554: 2:( )=4
555: 3:{ }=4
556: 4:[^({]=pop
557: */
558:
1.110 paf 559: static int yylex(YYSTYPE *lvalp, void *pc) {
1.114 paf 560: #define lexical_brackets_nestage PC.brackets_nestages[PC.sp]
1.48 paf 561: #define RC {result=c; goto break2; }
1.1 paf 562:
563: register int c;
564: int result;
565:
1.114 paf 566: if(PC.pending_state) {
567: result=PC.pending_state;
568: PC.pending_state=0;
1.1 paf 569: return result;
570: }
571:
1.114 paf 572: const char *begin=PC.source;
1.91 paf 573: const char *end;
1.114 paf 574: int begin_line=PC.line;
1.67 paf 575: int skip_analized=0;
1.50 paf 576: while(true) {
1.114 paf 577: c=*(end=(PC.source++));
1.1 paf 578:
1.4 paf 579: if(c=='\n') {
1.114 paf 580: PC.line++;
581: PC.col=0;
1.10 paf 582: } else
1.114 paf 583: PC.col++;
1.73 paf 584:
1.119 paf 585: if(c=='^' && PC.ls!=LS_COMMENT && PC.ls!=LS_DEF_COMMENT)
1.114 paf 586: switch(*PC.source) {
1.126 paf 587: // escaping: ^^ & co
1.48 paf 588: case '^': case '$': case ';':
1.126 paf 589: case '(': case ')':
1.48 paf 590: case '[': case ']':
591: case '{': case '}':
1.114 paf 592: case '"':
1.40 paf 593: if(end!=begin) {
594: // append piece till ^
1.121 paf 595: PC.string->APPEND_CLEAN(begin, end-begin, PC.file, begin_line);
1.40 paf 596: }
1.63 paf 597: // reset piece 'begin' position & line
1.114 paf 598: begin=PC.source; // ^
599: begin_line=PC.line;
1.40 paf 600: // skip over ^ and _
1.114 paf 601: PC.source++; PC.col++;
1.40 paf 602: // skip analysis = forced literal
1.1 paf 603: continue;
1.114 paf 604:
605: // converting ^#HH into char(hex(HH))
606: case '#':
607: if(end!=begin) {
608: // append piece till ^
1.121 paf 609: PC.string->APPEND_CLEAN(begin, end-begin, PC.file, begin_line);
1.114 paf 610: }
611: // #HH ?
612: if(PC.source[0]=='#' && PC.source[1] && PC.source[2]) {
613: char *hex=(char *)POOL.malloc(1);
614: hex[0]=
615: hex_value[(unsigned char)PC.source[1]]*0x10+
616: hex_value[(unsigned char)PC.source[2]];
617: if(hex[0]==0) {
618: result=BAD_HEX_LITERAL;
619: goto break2; // wrong hex value[no ^#00 chars allowed]: bail out
620: }
621: // append char(hex(HH))
1.121 paf 622: PC.string->APPEND_CLEAN(hex, 1, PC.file, begin_line);
1.114 paf 623: // skip over ^#HH
624: PC.source+=3;
625: PC.col+=3;
626: // reset piece 'begin' position & line
627: begin=PC.source; // ^
628: begin_line=PC.line;
629: continue;
630: }
631: break;
1.1 paf 632: }
1.113 paf 633: // #comment start skipping
1.114 paf 634: if(c=='#' && PC.col==1) {
1.112 paf 635: if(end!=begin) {
636: // append piece till #
1.121 paf 637: PC.string->APPEND_CLEAN(begin, end-begin, PC.file, begin_line);
1.112 paf 638: }
639: // fall into COMMENT lexical state [wait for \n]
640: push_LS(PC, LS_COMMENT);
641: }
1.114 paf 642: switch(PC.ls) {
1.10 paf 643:
644: // USER'S = NOT OURS
1.1 paf 645: case LS_USER:
1.153 parser 646: if(PC.trim_bof)
647: switch(c) {
648: case '\n': case ' ': case '\t':
1.152 parser 649: begin=PC.source;
650: begin_line=PC.line;
651: continue; // skip it
1.153 parser 652: default:
653: PC.trim_bof=false;
1.152 parser 654: }
1.48 paf 655: switch(c) {
656: case '$':
1.10 paf 657: push_LS(PC, LS_VAR_NAME_SIMPLE);
1.48 paf 658: RC;
659: case '^':
660: push_LS(PC, LS_METHOD_NAME);
661: RC;
662: case '@':
1.114 paf 663: if(PC.col==0+1) {
1.48 paf 664: push_LS(PC, LS_DEF_NAME);
665: RC;
666: }
667: break;
1.162 parser 668: case ']': // $name.(code<)>
1.160 parser 669: if(--lexical_brackets_nestage==0) {
670: pop_LS(PC);
671: RC;
672: }
673: break;
1.162 parser 674: case '[':
1.161 parser 675: lexical_brackets_nestage++;
676: break;
1.112 paf 677: }
678: break;
679:
680: // #COMMENT
681: case LS_COMMENT:
682: if(c=='\n') {
683: // skip comment
1.114 paf 684: begin=PC.source;
685: begin_line=PC.line;
1.112 paf 686:
687: pop_LS(PC);
688: continue;
1.1 paf 689: }
1.48 paf 690: break;
691:
692: // STRING IN EXPRESSION
1.145 parser 693: case LS_EXPRESSION_STRING_QUOTED:
694: case LS_EXPRESSION_STRING_APOSTROFED:
1.48 paf 695: switch(c) {
696: case '"':
1.145 parser 697: case '\'':
698: if(
699: PC.ls == LS_EXPRESSION_STRING_QUOTED && c=='"' ||
700: PC.ls == LS_EXPRESSION_STRING_APOSTROFED && c=='\'') {
701: pop_LS(PC); //"abc". | 'abc'.
702: RC;
703: }
704: break;
1.48 paf 705: case '$':
706: push_LS(PC, LS_VAR_NAME_SIMPLE);
707: RC;
708: case '^':
1.10 paf 709: push_LS(PC, LS_METHOD_NAME);
1.48 paf 710: RC;
1.10 paf 711: }
712: break;
713:
714: // METHOD DEFINITION
715: case LS_DEF_NAME:
1.48 paf 716: switch(c) {
717: case '[':
1.114 paf 718: PC.ls=LS_DEF_PARAMS;
1.48 paf 719: RC;
720: case '\n':
1.114 paf 721: PC.ls=LS_DEF_SPECIAL_BODY;
1.48 paf 722: RC;
1.10 paf 723: }
724: break;
1.48 paf 725:
1.10 paf 726: case LS_DEF_PARAMS:
1.48 paf 727: switch(c) {
728: case ';':
729: RC;
730: case ']':
1.114 paf 731: PC.ls=*PC.source=='['?LS_DEF_LOCALS:LS_DEF_COMMENT;
1.48 paf 732: RC;
1.49 paf 733: case '\n': // wrong. bailing out
1.10 paf 734: pop_LS(PC);
1.48 paf 735: RC;
1.10 paf 736: }
737: break;
1.48 paf 738:
1.10 paf 739: case LS_DEF_LOCALS:
1.48 paf 740: switch(c) {
741: case '[':
742: case ';':
743: RC;
744: case ']':
1.114 paf 745: PC.ls=LS_DEF_COMMENT;
1.48 paf 746: RC;
747: case '\n': // wrong. bailing out
1.10 paf 748: pop_LS(PC);
1.48 paf 749: RC;
1.10 paf 750: }
751: break;
1.48 paf 752:
1.10 paf 753: case LS_DEF_COMMENT:
754: if(c=='\n') {
755: pop_LS(PC);
1.48 paf 756: RC;
1.37 paf 757: }
758: break;
759:
1.48 paf 760: case LS_DEF_SPECIAL_BODY:
1.147 parser 761: // @todo in case
762: // ################
763: // @next-method
764: // we are here with c=='@'
765: // which is wrong, and need action
1.37 paf 766: if(c=='\n') {
1.114 paf 767: switch(*PC.source) {
1.48 paf 768: case '@': case 0: // end of special_code
1.37 paf 769: pop_LS(PC);
1.48 paf 770: break;
771: }
772: RC;
773: }
774: break;
775:
776: // (EXPRESSION)
1.69 paf 777: case LS_VAR_ROUND:
778: case LS_METHOD_ROUND:
1.48 paf 779: switch(c) {
780: case ')':
781: if(--lexical_brackets_nestage==0)
1.114 paf 782: if(PC.ls==LS_METHOD_ROUND) // method round param ended
783: PC.ls=LS_METHOD_AFTER; // look for method end
784: else // PC.ls==LS_VAR_ROUND // variable constructor ended
1.69 paf 785: pop_LS(PC); // return to normal life
1.48 paf 786: RC;
787: case '$':
1.69 paf 788: push_LS(PC, LS_EXPRESSION_VAR_NAME);
1.48 paf 789: RC;
790: case '^':
791: push_LS(PC, LS_METHOD_NAME);
792: RC;
793: case '(':
794: lexical_brackets_nestage++;
795: RC;
1.67 paf 796: case '-':
1.127 paf 797: switch(*PC.source) {
798: case 'f': // -f
1.67 paf 799: skip_analized=1;
800: result=FEXISTS;
1.127 paf 801: goto break2;
802: case 'd': // -d
803: skip_analized=1;
804: result=DEXISTS;
805: goto break2;
806: default:
1.67 paf 807: result=c;
1.127 paf 808: goto break2;
809: }
1.67 paf 810: goto break2;
811: case '+': case '*': case '/': case '%':
1.58 paf 812: case '~':
1.48 paf 813: case ';':
814: RC;
1.59 paf 815: case '&': case '|': case '#':
1.114 paf 816: if(*PC.source==c) { // && ||
1.59 paf 817: result=c=='#'?LXOR:c=='&'?LAND:LOR;
1.67 paf 818: skip_analized=1;
1.58 paf 819: } else
820: result=c;
821: goto break2;
822: case '<': case '>': case '=': case '!':
1.114 paf 823: if(*PC.source=='=') { // <= >= == !=
1.67 paf 824: skip_analized=1;
1.58 paf 825: switch(c) {
826: case '<': result=NLE; break;
827: case '>': result=NGE; break;
828: case '=': result=NEQ; break;
829: case '!': result=NNE; break;
830: }
831: } else
832: result=c;
833: goto break2;
1.48 paf 834: case '"':
1.145 parser 835: push_LS(PC, LS_EXPRESSION_STRING_QUOTED);
836: RC;
837: case '\'':
838: push_LS(PC, LS_EXPRESSION_STRING_APOSTROFED);
1.48 paf 839: RC;
1.50 paf 840: case 'l': case 'g': case 'e': case 'n':
1.51 paf 841: if(end==begin) // right after whitespace
1.117 paf 842: if(isspace(PC.source[1])) {
843: switch(*PC.source) {
844: // case '?': // ok [and bad cases, yacc would bark at them]
845: case 't': // lt gt [et nt]
846: result=c=='l'?SLT:c=='g'?SGT:BAD_STRING_COMPARISON_OPERATOR;
847: skip_analized=1;
848: goto break2;
849: case 'e': // le ge ne [ee]
850: result=c=='l'?SLE:c=='g'?SGE:c=='n'?SNE:BAD_STRING_COMPARISON_OPERATOR;
851: skip_analized=1;
852: goto break2;
853: case 'q': // eq [lq gq nq]
854: result=c=='e'?SEQ:BAD_STRING_COMPARISON_OPERATOR;
855: skip_analized=1;
856: goto break2;
857: }
1.67 paf 858: }
859: break;
860: case 'i':
861: if(end==begin) // right after whitespace
1.117 paf 862: if(isspace(PC.source[1])) {
863: switch(PC.source[0]) {
864: case 'n': // in
1.95 paf 865: skip_analized=1;
866: result=IN;
867: goto break2;
1.117 paf 868: case 's': // is
1.95 paf 869: skip_analized=1;
870: result=IS;
871: goto break2;
872: }
1.67 paf 873: }
874: break;
875: case 'd':
876: if(end==begin) // right after whitespace
1.114 paf 877: if(PC.source[0]=='e' && PC.source[1]=='f') { // def
1.67 paf 878: skip_analized=2;
879: result=DEF;
1.58 paf 880: goto break2;
1.50 paf 881: }
1.48 paf 882: break;
883: case ' ': case '\t': case '\n':
1.63 paf 884: if(end!=begin) { // there were a string after previous operator?
885: result=0; // return that string
886: goto break2;
1.48 paf 887: }
1.63 paf 888: // that's a leading|traling space or after-operator-space
889: // ignoring it
890: // reset piece 'begin' position & line
1.114 paf 891: begin=PC.source; // after whitespace char
892: begin_line=PC.line;
1.48 paf 893: continue;
1.1 paf 894: }
895: break;
896:
1.10 paf 897: // VARIABLE GET/PUT/WITH
1.1 paf 898: case LS_VAR_NAME_SIMPLE:
1.69 paf 899: case LS_EXPRESSION_VAR_NAME:
1.142 parser 900: case LS_VAR_NAME_NO_COLON:
1.114 paf 901: if(PC.ls==LS_EXPRESSION_VAR_NAME) {
1.56 paf 902: // name in expr ends also before binary operators
1.48 paf 903: switch(c) {
1.92 paf 904: case '-':
1.48 paf 905: pop_LS(PC);
1.114 paf 906: PC.source--; if(--PC.col<0) { PC.line--; PC.col=-1; }
1.48 paf 907: result=EON;
908: goto break2;
909: }
910: }
1.142 parser 911: if(PC.ls==LS_VAR_NAME_NO_COLON) {
912: // name already has ':', stop before next
913: switch(c) {
914: case ':':
915: pop_LS(PC);
916: PC.source--; if(--PC.col<0) { PC.line--; PC.col=-1; }
917: result=EON;
918: goto break2;
919: }
920: }
1.48 paf 921: switch(c) {
922: case 0:
923: case ' ': case '\t': case '\n':
924: case ';':
1.126 paf 925: case ']': case '}': case ')':
926: case '"': case '\'':
1.139 parser 927: case '<': case '>': // these stand for HTML brackets AND expression binary ops
1.92 paf 928: case '+': case '*': case '/': case '%':
929: case '&': case '|':
930: case '=': case '!':
1.99 paf 931: // common delimiters
1.158 parser 932: case ',': case '?':
1.139 parser 933: // before call
934: case '^':
1.1 paf 935: pop_LS(PC);
1.114 paf 936: PC.source--; if(--PC.col<0) { PC.line--; PC.col=-1; }
1.13 paf 937: result=EON;
1.1 paf 938: goto break2;
1.48 paf 939: case '[':
1.162 parser 940: // $name.<[>code]
941: if(PC.col>1/*not first column*/ && (
1.163 ! parser 942: end[-1]=='$'/*was start of get*/ ||
! 943: end[-1]==':'/*was class name delim */ ||
! 944: end[-1]=='.'/*was name delim */
1.162 parser 945: )) {
946: push_LS(PC, LS_USER);
947: lexical_brackets_nestage=1;
948: RC;
949: }
1.114 paf 950: PC.ls=LS_VAR_SQUARE;
1.1 paf 951: lexical_brackets_nestage=1;
1.48 paf 952: RC;
953: case '{':
954: if(begin==end) { // ${name}, no need of EON, switching LS
1.114 paf 955: PC.ls=LS_VAR_NAME_CURLY;
1.48 paf 956: } else {
1.114 paf 957: PC.ls=LS_VAR_CURLY;
1.48 paf 958: lexical_brackets_nestage=1;
959: }
1.69 paf 960:
1.48 paf 961: RC;
962: case '(':
1.114 paf 963: PC.ls=LS_VAR_ROUND;
1.1 paf 964: lexical_brackets_nestage=1;
1.48 paf 965: RC;
966: case '.': // name part delim
967: case '$': // name part subvar
1.160 parser 968: case ':': // class<:>name
1.142 parser 969: PC.ls=LS_VAR_NAME_NO_COLON; // stop before next ':'
1.48 paf 970: RC;
1.1 paf 971: }
972: break;
1.48 paf 973:
1.1 paf 974: case LS_VAR_NAME_CURLY:
1.48 paf 975: switch(c) {
1.162 parser 976: case '[':
977: // ${name.<[>code)}
1.160 parser 978: push_LS(PC, LS_USER);
979: lexical_brackets_nestage=1;
980: RC;
1.48 paf 981: case '}': // ${name} finished, restoring LS
1.1 paf 982: pop_LS(PC);
1.48 paf 983: RC;
984: case '.': // name part delim
985: case '$': // name part subvar
986: case ':': // ':name' or 'class:name'
987: RC;
1.1 paf 988: }
989: break;
1.48 paf 990:
991: case LS_VAR_SQUARE:
992: switch(c) {
993: case '$':
1.10 paf 994: push_LS(PC, LS_VAR_NAME_SIMPLE);
1.48 paf 995: RC;
996: case '^':
1.10 paf 997: push_LS(PC, LS_METHOD_NAME);
1.48 paf 998: RC;
999: case ']':
1.1 paf 1000: if(--lexical_brackets_nestage==0) {
1001: pop_LS(PC);
1.48 paf 1002: RC;
1.1 paf 1003: }
1.48 paf 1004: break;
1005: case ';': // operator_or_fmt;value delim
1006: RC;
1007: case '[':
1008: lexical_brackets_nestage++;
1009: break;
1.1 paf 1010: }
1011: break;
1.48 paf 1012:
1.1 paf 1013: case LS_VAR_CURLY:
1.48 paf 1014: switch(c) {
1015: case '$':
1.10 paf 1016: push_LS(PC, LS_VAR_NAME_SIMPLE);
1.48 paf 1017: RC;
1018: case '^':
1.10 paf 1019: push_LS(PC, LS_METHOD_NAME);
1.48 paf 1020: RC;
1021: case '}':
1.1 paf 1022: if(--lexical_brackets_nestage==0) {
1023: pop_LS(PC);
1.48 paf 1024: RC;
1.1 paf 1025: }
1.48 paf 1026: break;
1027: case '{':
1.1 paf 1028: lexical_brackets_nestage++;
1.48 paf 1029: break;
1030: }
1.1 paf 1031: break;
1032:
1.10 paf 1033: // METHOD CALL
1.1 paf 1034: case LS_METHOD_NAME:
1.48 paf 1035: switch(c) {
1036: case '[':
1.162 parser 1037: // $name.<[>code)
1038: if(PC.col>1/*not first column*/ && (
1.163 ! parser 1039: end[-1]=='^'/*was start of call*/ || // never, ^[ is literal...
! 1040: end[-1]==':'/*was class name delim */ ||
! 1041: end[-1]=='.'/*was name delim */
1.162 parser 1042: )) {
1043: push_LS(PC, LS_USER);
1044: lexical_brackets_nestage=1;
1045: RC;
1046: }
1.114 paf 1047: PC.ls=LS_METHOD_SQUARE;
1.1 paf 1048: lexical_brackets_nestage=1;
1.48 paf 1049: RC;
1050: case '{':
1.114 paf 1051: PC.ls=LS_METHOD_CURLY;
1.1 paf 1052: lexical_brackets_nestage=1;
1.48 paf 1053: RC;
1.69 paf 1054: case '(':
1.114 paf 1055: PC.ls=LS_METHOD_ROUND;
1.69 paf 1056: lexical_brackets_nestage=1;
1057: RC;
1.48 paf 1058: case '.': // name part delim
1059: case '$': // name part subvar
1060: case ':': // ':name' or 'class:name'
1061: RC;
1.1 paf 1062: }
1063: break;
1.48 paf 1064:
1065: case LS_METHOD_SQUARE:
1066: switch(c) {
1067: case '$':
1.10 paf 1068: push_LS(PC, LS_VAR_NAME_SIMPLE);
1.48 paf 1069: RC;
1070: case '^':
1.10 paf 1071: push_LS(PC, LS_METHOD_NAME);
1.48 paf 1072: RC;
1073: case ';': // param delim
1074: RC;
1075: case ']':
1.1 paf 1076: if(--lexical_brackets_nestage==0) {
1.114 paf 1077: PC.ls=LS_METHOD_AFTER;
1.48 paf 1078: RC;
1.1 paf 1079: }
1.48 paf 1080: break;
1081: case '[':
1.1 paf 1082: lexical_brackets_nestage++;
1.48 paf 1083: break;
1084: }
1.1 paf 1085: break;
1.48 paf 1086:
1.1 paf 1087: case LS_METHOD_CURLY:
1.48 paf 1088: switch(c) {
1089: case '$':
1.10 paf 1090: push_LS(PC, LS_VAR_NAME_SIMPLE);
1.48 paf 1091: RC;
1092: case '^':
1.10 paf 1093: push_LS(PC, LS_METHOD_NAME);
1.94 paf 1094: RC;
1095: case ';': // param delim
1.48 paf 1096: RC;
1097: case '}':
1.1 paf 1098: if(--lexical_brackets_nestage==0) {
1.114 paf 1099: PC.ls=LS_METHOD_AFTER;
1.48 paf 1100: RC;
1.1 paf 1101: }
1.48 paf 1102: break;
1103: case '{':
1.1 paf 1104: lexical_brackets_nestage++;
1.48 paf 1105: break;
1106: }
1.1 paf 1107: break;
1.48 paf 1108:
1.1 paf 1109: case LS_METHOD_AFTER:
1.69 paf 1110: if(c=='[') {/* ][ }[ )[ */
1.114 paf 1111: PC.ls=LS_METHOD_SQUARE;
1.1 paf 1112: lexical_brackets_nestage=1;
1.48 paf 1113: RC;
1.1 paf 1114: }
1.69 paf 1115: if(c=='{') {/* ]{ }{ ){ */
1.114 paf 1116: PC.ls=LS_METHOD_CURLY;
1.69 paf 1117: lexical_brackets_nestage=1;
1118: RC;
1119: }
1120: if(c=='(') {/* ]( }( )( */
1.114 paf 1121: PC.ls=LS_METHOD_ROUND;
1.1 paf 1122: lexical_brackets_nestage=1;
1.48 paf 1123: RC;
1.1 paf 1124: }
1125: pop_LS(PC);
1.114 paf 1126: PC.source--; if(--PC.col<0) { PC.line--; PC.col=-1; }
1.13 paf 1127: result=EON;
1.1 paf 1128: goto break2;
1129: }
1.9 paf 1130: if(c==0) {
1.1 paf 1131: result=-1;
1132: break;
1133: }
1134: }
1135:
1136: break2:
1.59 paf 1137: if(end!=begin) { // there is last piece?
1138: if((c=='@' || c==0) && end[-1]=='\n') { // we are before LS_DEF_NAME or EOF?
1139: // strip last \n
1.10 paf 1140: end--;
1.137 parser 1141: if(end!=begin && end[-1]=='\n') // allow one empty line before LS_DEF_NAME
1142: end--;
1.59 paf 1143: }
1.133 parser 1144: if(end!=begin && PC.ls!=LS_COMMENT) { // last piece still alive and not comment?
1.59 paf 1145: // append it
1.121 paf 1146: PC.string->APPEND_CLEAN(begin, end-begin, PC.file, begin_line/*, start_col*/);
1.30 paf 1147: }
1.59 paf 1148: }
1.114 paf 1149: if(PC.string->size()) { // something accumulated?
1.17 paf 1150: // create STRING value: array of OP_VALUE+vstring
1.114 paf 1151: *lvalp=VL(NEW VString(*PC.string));
1.10 paf 1152: // new pieces storage
1.114 paf 1153: PC.string=NEW String(POOL);
1.58 paf 1154: // make current result be pending for next call, return STRING for now
1.114 paf 1155: PC.pending_state=result; result=STRING;
1.58 paf 1156: }
1.67 paf 1157: if(skip_analized) {
1.114 paf 1158: PC.source+=skip_analized; PC.col+=skip_analized;
1.1 paf 1159: }
1.58 paf 1160: return result;
1.1 paf 1161: }
1162:
1.110 paf 1163: static int real_yyerror(parse_control *pc, char *s) { // Called by yyparse on error
1.114 paf 1164: strncpy(PC.error, s, MAX_STRING);
1.1 paf 1165: return 1;
1.110 paf 1166: }
1.1 paf 1167:
1.110 paf 1168: static void yyprint(FILE *file, int type, YYSTYPE value) {
1169: if(type==STRING)
1.120 paf 1170: fprintf(file, " \"%s\"", LA2S(value)->cstr());
1.110 paf 1171: }
E-mail: