Annotation of parser3/src/main/compile.y, revision 1.50
1.24 paf 1: /*
1.50 ! paf 2: $Id: compile.y,v 1.49 2001/03/06 12:22:58 paf Exp $
1.24 paf 3: */
4:
1.1 paf 5: %{
1.9 paf 6: #define YYSTYPE Array/*<op>*/ *
7: #define YYPARSE_PARAM pc
8: #define YYLEX_PARAM pc
9: #define YYDEBUG 1
1.1 paf 10: #define YYERROR_VERBOSE
1.9 paf 11: #define yyerror(msg) real_yyerror((parse_control *)pc, msg)
12: #define YYPRINT(file, type, value) yyprint(file, type, value)
1.1 paf 13:
14: #include <stdio.h>
15: #include <string.h>
16: #include <stdlib.h>
17:
18: #include "compile_tools.h"
1.8 paf 19: #include "pa_value.h"
1.12 paf 20: #include "pa_request.h"
1.39 paf 21: #include "pa_vobject.h"
22:
23: #define SELF_NAME "self"
24: #define USES_NAME "USES"
1.1 paf 25:
1.9 paf 26: int real_yyerror(parse_control *pc, char *s);
27: static void yyprint(FILE *file, int type, YYSTYPE value);
1.1 paf 28: int yylex(YYSTYPE *lvalp, void *pc);
29:
30:
1.8 paf 31: // local convinient inplace typecast & var
1.9 paf 32: #define PC ((parse_control *)pc)
1.25 paf 33: #define POOL *PC->pool
34: #undef NEW
35: #define NEW new(POOL)
1.1 paf 36: %}
37:
38: %pure_parser
39:
1.13 paf 40: %token EON
1.4 paf 41: %token STRING
1.1 paf 42: %token BOGUS
1.50 ! paf 43: %token LOGICAL_AND LOGICAL_OR
1.1 paf 44:
45: %%
46:
1.10 paf 47: all:
48: one_big_piece {
1.25 paf 49: String& name_main=*NEW String(POOL);
1.11 paf 50: name_main.APPEND_CONST(MAIN_METHOD_NAME);
1.25 paf 51: Array& param_names=*NEW Array(POOL);
52: Array& local_names=*NEW Array(POOL);
1.34 paf 53: Method& method=*NEW Method(POOL, name_main, param_names, local_names, *$1);
54: PC->vclass->add_method(name_main, method);
1.10 paf 55: }
56: | methods;
57:
58: methods: method | methods method;
59: one_big_piece: maybe_codes;
60:
1.34 paf 61: method: control_method | code_method;
62:
63: control_method: '@' STRING '\n'
64: control_strings {
1.38 paf 65: String& name=*SLA2S($2);
1.34 paf 66: YYSTYPE strings_code=$4;
1.37 paf 67: if(strings_code->size()<1*2) {
68: strcpy(PC->error, "@");
69: strcat(PC->error, name.cstr());
70: strcat(PC->error, " is empty");
71: YYERROR;
72: }
1.36 paf 73: if(name==CLASS_NAME) {
1.34 paf 74: if(strings_code->size()==1*2)
1.38 paf 75: PC->vclass->set_name(*SLA2S(strings_code));
1.34 paf 76: else {
77: strcpy(PC->error, "@"CLASS_NAME" must contain sole name");
78: YYERROR;
79: }
80: } else {
1.36 paf 81: if(name==USES_NAME) {
1.34 paf 82: for(int i=0; i<strings_code->size(); i+=2) {
1.38 paf 83: String *file=SLA2S(strings_code, i);
1.35 paf 84: file->APPEND_CONST(".p");
85: PC->request->use(file->cstr(), 0);
1.34 paf 86: }
1.45 paf 87: } else if(name==BASE_NAME) {
88: if(strings_code->size()==1*2) {
89: String& base_name=*SLA2S(strings_code);
90: VClass *base=static_cast<VClass *>(
91: PC->request->classes().get(base_name));
92: if(!base) {
93: strcpy(PC->error, base_name.cstr());
94: strcat(PC->error, ": undefined class in @"BASE_NAME);
1.34 paf 95: YYERROR;
96: }
1.45 paf 97: PC->vclass->set_base(*base);
98: } else {
99: strcpy(PC->error, "@"BASE_NAME" must contain sole name");
100: YYERROR;
1.34 paf 101: }
102: } else {
1.36 paf 103: strcpy(PC->error, name.cstr());
1.34 paf 104: strcat(PC->error, ": invalid special name. valid names are "
1.45 paf 105: CLASS_NAME", "USES_NAME" and "BASE_NAME);
1.34 paf 106: YYERROR;
107: }
108: }
109: };
1.37 paf 110: control_strings: control_string | control_strings control_string { $$=$1; P($$, $2) };
111: control_string: maybe_string '\n';
112: maybe_string: empty | STRING;
1.34 paf 113:
114: code_method: '@' STRING bracketed_maybe_strings maybe_bracketed_strings maybe_comment '\n'
1.10 paf 115: maybe_codes {
1.38 paf 116: const String *name=SLA2S($2);
1.10 paf 117:
118: YYSTYPE params_names_code=$3;
1.25 paf 119: Array& params_names=*NEW Array(POOL);
1.10 paf 120: for(int i=0; i<params_names_code->size(); i+=2)
1.38 paf 121: params_names+=SLA2S(params_names_code, i);
1.10 paf 122:
123: YYSTYPE locals_names_code=$4;
1.25 paf 124: Array& locals_names=*NEW Array(POOL);
1.10 paf 125: for(int i=0; i<locals_names_code->size(); i+=2)
1.38 paf 126: locals_names+=SLA2S(locals_names_code, i);
1.10 paf 127:
1.34 paf 128: Method& method=*NEW Method(POOL, *name, params_names, locals_names, *$7);
129: PC->vclass->add_method(*name, method);
1.8 paf 130: };
1.10 paf 131:
132: maybe_bracketed_strings: empty | bracketed_maybe_strings;
133: bracketed_maybe_strings: '[' maybe_strings ']' {$$=$2};
134: maybe_strings: empty | strings;
135: strings: STRING | strings ';' STRING { $$=$1; P($$, $3) };
136:
137: maybe_comment: empty | STRING;
1.1 paf 138:
139: /* codes */
140:
1.10 paf 141: maybe_codes: empty | codes;
142:
1.1 paf 143: codes: code | codes code {
144: $$=$1;
1.9 paf 145: P($$, $2);
1.1 paf 146: };
147: code: write_str_literal | action;
148: action: get | put | with | call;
149:
150: /* get */
151:
1.42 paf 152: get: '$' get_name {
1.1 paf 153: $$=$2; /* stack: resulting value */
1.17 paf 154: OP($$, OP_WRITE); /* value=pop; write(value) */
1.1 paf 155: };
1.43 paf 156: get_name: name_without_curly_rdive EON | name_in_curly_rdive;
1.1 paf 157: name_in_curly_rdive: '{' name_without_curly_rdive '}' { $$=$2 };
1.44 paf 158: name_without_curly_rdive:
159: name_without_curly_rdive_read
160: | name_without_curly_rdive_root
161: | name_without_curly_rdive_class;
1.19 paf 162: name_without_curly_rdive_read: name_without_curly_rdive_code {
1.25 paf 163: $$=N(POOL);
1.22 paf 164: Array *diving_code=$1;
1.38 paf 165: String *first_name=SLA2S(diving_code);
1.23 paf 166: if(first_name && *first_name==SELF_NAME) {
1.22 paf 167: OP($$, OP_WITH_SELF); /* stack: starting context */
168: P($$, diving_code,
169: /* skip over... */
170: diving_code->size()>2?3/*OP_+string+get_element*/:2/*OP_+string*/);
171: } else {
172: OP($$, OP_WITH_READ); /* stack: starting context */
173: P($$, diving_code);
174: }
175: /* diving code; stack: current context */
1.1 paf 176: };
1.19 paf 177: name_without_curly_rdive_root: ':' name_without_curly_rdive_code {
1.25 paf 178: $$=N(POOL);
1.19 paf 179: OP($$, OP_WITH_ROOT); /* stack: starting context */
180: P($$, $2); /* diving code; stack: current context */
181: };
1.44 paf 182: name_without_curly_rdive_class: class_prefix name_without_curly_rdive_code { $$=$1; P($$, $2) };
1.19 paf 183: name_without_curly_rdive_code: name_advance2 | name_path name_advance2 { $$=$1; P($$, $2) };
1.1 paf 184:
185: /* put */
186:
1.47 paf 187: put: '$' name_expr_wdive '[' constructor_value ']' {
1.20 paf 188: $$=$2; /* stack: context,name */
189: P($$, $4); /* stack: context,name,constructor_value */
190: OP($$, OP_CONSTRUCT); /* value=pop; name=pop; context=pop; construct(context,name,value) */
191: };
1.44 paf 192: name_expr_wdive:
193: name_expr_wdive_write
194: | name_expr_wdive_root
195: | name_expr_wdive_class;
1.28 paf 196: name_expr_wdive_write: name_expr_dive_code {
1.44 paf 197: $$=N(POOL);
1.23 paf 198: Array *diving_code=$1;
1.38 paf 199: String *first_name=SLA2S(diving_code);
1.23 paf 200: if(first_name && *first_name==SELF_NAME) {
201: OP($$, OP_WITH_SELF); /* stack: starting context */
202: P($$, diving_code,
203: /* skip over... */
204: diving_code->size()>2?3/*OP_+string+get_element*/:2/*OP_+string*/);
205: } else {
206: OP($$, OP_WITH_WRITE); /* stack: starting context */
207: P($$, diving_code);
208: }
209: /* diving code; stack: current context */
1.20 paf 210: };
1.28 paf 211: name_expr_wdive_root: ':' name_expr_dive_code {
1.25 paf 212: $$=N(POOL);
1.20 paf 213: OP($$, OP_WITH_ROOT); /* stack: starting context */
1.9 paf 214: P($$, $2); /* diving code; stack: context,name */
1.1 paf 215: };
1.44 paf 216: name_expr_wdive_class: class_prefix name_expr_dive_code { $$=$1; P($$, $2) };
1.20 paf 217:
1.1 paf 218: constructor_value:
1.32 paf 219: empty_value /* optimized $var() case */
220: | STRING /* optimized $var(STRING) case */
221: | complex_constructor_param_value /* $var(something complex) */
1.1 paf 222: ;
223: complex_constructor_param_value: complex_constructor_param_body {
1.25 paf 224: $$=N(POOL);
1.3 paf 225: OP($$, OP_CREATE_EWPOOL); /* stack: empty write context */
1.9 paf 226: P($$, $1); /* some codes to that context */
227: OP($$, OP_REDUCE_EWPOOL); /* context=pop; stack: context.value() */
1.1 paf 228: };
1.27 paf 229: complex_constructor_param_body: codes__excluding_sole_str_literal;
230: codes__excluding_sole_str_literal: action | code codes { $$=$1; P($$, $2) };
231:
1.1 paf 232: /* call */
233:
1.38 paf 234: call: '^' call_name store_params EON { /* ^field.$method{vasya} */
1.42 paf 235: $$=$2; /* with_xxx,diving code; stack: context,method_junction */
1.9 paf 236: OP($$, OP_GET_METHOD_FRAME); /* stack: context,method_frame */
237: P($$, $3); /* filling method_frame.store_params */
238: OP($$, OP_CALL); /* method_frame=pop; ncontext=pop; call(ncontext,method_frame) */
1.1 paf 239: };
240:
1.43 paf 241: call_name: name_without_curly_rdive;
1.38 paf 242:
1.9 paf 243: store_params: store_param | store_params store_param { $$=$1; P($$, $2) };
1.1 paf 244: store_param: store_round_param | store_curly_param;
1.47 paf 245: store_round_param: '[' store_param_parts ']' {$$=$2};
1.31 paf 246: store_param_parts:
1.32 paf 247: store_param_part
248: | store_param_parts ';' store_param_part { $$=$1; P($$, $3) }
1.31 paf 249: ;
1.10 paf 250: store_curly_param: '{' maybe_codes '}' {
1.25 paf 251: $$=N(POOL);
1.29 paf 252: PCA($$, $2);
1.9 paf 253: OP($$, OP_STORE_PARAM);
1.1 paf 254: };
1.32 paf 255: store_param_part:
1.33 paf 256: empty /* optimized () case */
257: | STRING { /* optimized (STRING) case */
1.32 paf 258: $$=$1;
259: OP($$, OP_STORE_PARAM);
260: }
1.33 paf 261: | complex_constructor_param_value { /* (something complex) */
1.32 paf 262: $$=$1;
263: OP($$, OP_STORE_PARAM);
264: }
265: ;
1.1 paf 266:
267: /* name */
268:
1.20 paf 269: name_expr_dive_code: name_expr_value | name_path name_expr_value { $$=$1; P($$, $2) };
1.1 paf 270:
1.9 paf 271: name_path: name_step | name_path name_step { $$=$1; P($$, $2) };
1.1 paf 272: name_step: name_advance1 '.';
273: name_advance1: name_expr_value {
274: /* stack: context */
275: $$=$1; /* stack: context,name */
1.9 paf 276: OP($$, OP_GET_ELEMENT); /* name=pop; context=pop; stack: context.get_element(name) */
1.1 paf 277: };
278: name_advance2: name_expr_value {
279: /* stack: context */
280: $$=$1; /* stack: context,name */
1.9 paf 281: OP($$, OP_GET_ELEMENT); /* name=pop; context=pop; stack: context.get_element(name) */
1.1 paf 282: }
1.4 paf 283: | STRING BOGUS
1.1 paf 284: ;
285: name_expr_value:
1.4 paf 286: STRING /* subname_is_const */
1.1 paf 287: | name_expr_subvar_value /* $subname_is_var_value */
288: | name_expr_with_subvar_value /* xxx$part_of_subname_is_var_value[$...] */
289: ;
290: name_expr_subvar_value: '$' subvar_ref_name_rdive {
291: $$=$2;
1.9 paf 292: OP($$, OP_GET_ELEMENT);
1.1 paf 293: };
1.4 paf 294: name_expr_with_subvar_value: STRING subvar_get_writes {
1.25 paf 295: $$=N(POOL);
1.3 paf 296: OP($$, OP_CREATE_EWPOOL);
1.9 paf 297: P($$, $1);
1.17 paf 298: OP($$, OP_WRITE);
1.9 paf 299: P($$, $2);
300: OP($$, OP_REDUCE_EWPOOL);
1.1 paf 301: };
1.18 paf 302: subvar_ref_name_rdive: subvar_ref_name_rdive_read | subvar_ref_name_rdive_root;
303: subvar_ref_name_rdive_read: STRING {
1.25 paf 304: $$=N(POOL);
1.18 paf 305: OP($$, OP_WITH_READ);
1.9 paf 306: P($$, $1);
1.1 paf 307: };
1.18 paf 308: subvar_ref_name_rdive_root: ':' STRING {
1.25 paf 309: $$=N(POOL);
1.18 paf 310: OP($$, OP_WITH_ROOT);
311: P($$, $2);
312: };
1.9 paf 313: subvar_get_writes: subvar__get_write | subvar_get_writes subvar__get_write { $$=$1; P($$, $2) };
1.1 paf 314: subvar__get_write: '$' subvar_ref_name_rdive {
315: $$=$2;
1.17 paf 316: OP($$, OP_GET_ELEMENT__WRITE);
1.42 paf 317: };
318:
1.44 paf 319: class_prefix: STRING ':' {
1.42 paf 320: String& name=*SLA2S($1);
321: VClass *vclass=static_cast<VClass *>(PC->request->classes().get(name));
322: if(!vclass) {
323: strcpy(PC->error, "'");
324: strcat(PC->error, name.cstr());
325: strcat(PC->error, "' class is undefined in call");
326: YYERROR;
327: }
1.48 paf 328: //TODO: убрать зависимость от статических @USE, сделать имя, а не ссылку
1.42 paf 329: $$=CL(vclass); // vclass
1.1 paf 330: };
331:
332:
333: /* with */
334:
335: with: '$' name_without_curly_rdive '{' codes '}' {
336: $$=$2;
1.9 paf 337: OP($$, OP_CREATE_RWPOOL);
338: P($$, $4);
339: OP($$, OP_REDUCE_RWPOOL);
1.17 paf 340: OP($$, OP_WRITE);
1.1 paf 341: };
342:
1.27 paf 343: /* basics */
1.1 paf 344:
1.4 paf 345: write_str_literal: STRING {
1.38 paf 346: if(SLA2S($1)->size()) {
1.30 paf 347: $$=$1;
348: OP($$, OP_WRITE);
349: } else {
350: // optimized case of special end of macro. see yylex
351: $$=N(POOL);
352: }
1.26 paf 353: };
1.38 paf 354: empty_value: /* empty */ { $$=SL(NEW VString(POOL)) };
1.25 paf 355: empty: /* empty */ { $$=N(POOL) };
1.1 paf 356:
357: %%
358:
359: /*
360: 000$111(2222)00
361: 000$111{3333}00
1.9 paf 362: $,^: push,=0
1.1 paf 363: 1:( { break=pop
364: 2:( ) pop
365: 3:{ } pop
366:
367: 000^111(2222)4444{33333}4000
1.9 paf 368: $,^: push,=0
1.1 paf 369: 1:( { break=pop
370: 2:( )=4
371: 3:{ }=4
372: 4:[^({]=pop
373: */
374:
375: int yylex(YYSTYPE *lvalp, void *pc) {
376: #define lexical_brackets_nestage PC->brackets_nestages[PC->sp]
1.48 paf 377: #define RC {result=c; goto break2; }
1.1 paf 378:
379: register int c;
380: int result;
381:
382: if(PC->pending_state) {
383: result=PC->pending_state;
384: PC->pending_state=0;
385: return result;
386: }
387:
1.9 paf 388: char *begin=PC->source;
389: char *end;
390: int begin_line=PC->line;
1.50 ! paf 391: while(true) {
1.9 paf 392: c=*(end=(PC->source++));
1.1 paf 393:
1.4 paf 394: if(c=='\n') {
1.1 paf 395: PC->line++;
1.8 paf 396: PC->col=0;
1.10 paf 397: } else
1.4 paf 398: PC->col++;
1.1 paf 399:
1.48 paf 400: // escaping: ^^ ^$ ^; ^) ^} ^( ^{ ^"
401: if(c=='^')
402: switch(*PC->source) {
403: case '^': case '$': case ';':
404: case '[': case ']':
405: case '{': case '}':
406: case '"':
1.40 paf 407: if(end!=begin) {
408: // append piece till ^
409: PC->string->APPEND(begin, end-begin, PC->file, begin_line);
410: }
411: // reset piece 'start' position & line
412: begin=PC->source; // ^
1.9 paf 413: begin_line=PC->line;
1.40 paf 414: // skip over ^ and _
1.50 ! paf 415: PC->source++; PC->col++;
1.40 paf 416: // skip analysis = forced literal
1.1 paf 417: continue;
418: }
419: switch(PC->ls) {
1.10 paf 420:
421: // USER'S = NOT OURS
1.1 paf 422: case LS_USER:
1.48 paf 423: switch(c) {
424: case '$':
1.10 paf 425: push_LS(PC, LS_VAR_NAME_SIMPLE);
1.48 paf 426: RC;
427: case '^':
428: push_LS(PC, LS_METHOD_NAME);
429: RC;
430: case '@':
431: if(PC->col==0+1) {
432: push_LS(PC, LS_DEF_NAME);
433: RC;
434: }
435: break;
1.1 paf 436: }
1.48 paf 437: break;
438:
439: // STRING IN EXPRESSION
440: case LS_EXPRESSION_STRING:
441: switch(c) {
442: case '"':
443: pop_LS(PC); //"abc".
444: RC;
445: case '$':
446: push_LS(PC, LS_VAR_NAME_SIMPLE);
447: RC;
448: case '^':
1.10 paf 449: push_LS(PC, LS_METHOD_NAME);
1.48 paf 450: RC;
1.10 paf 451: }
452: break;
453:
454: // METHOD DEFINITION
455: case LS_DEF_NAME:
1.48 paf 456: switch(c) {
457: case '[':
1.10 paf 458: PC->ls=LS_DEF_PARAMS;
1.48 paf 459: RC;
460: case '\n':
461: PC->ls=LS_DEF_SPECIAL_BODY;
462: RC;
1.10 paf 463: }
464: break;
1.48 paf 465:
1.10 paf 466: case LS_DEF_PARAMS:
1.48 paf 467: switch(c) {
468: case ';':
469: RC;
470: case ']':
1.10 paf 471: PC->ls=*PC->source=='['?LS_DEF_LOCALS:LS_DEF_COMMENT;
1.48 paf 472: RC;
1.49 paf 473: case '\n': // wrong. bailing out
1.10 paf 474: pop_LS(PC);
1.48 paf 475: RC;
1.10 paf 476: }
477: break;
1.48 paf 478:
1.10 paf 479: case LS_DEF_LOCALS:
1.48 paf 480: switch(c) {
481: case '[':
482: case ';':
483: RC;
484: case ']':
1.10 paf 485: PC->ls=LS_DEF_COMMENT;
1.48 paf 486: RC;
487: case '\n': // wrong. bailing out
1.10 paf 488: pop_LS(PC);
1.48 paf 489: RC;
1.10 paf 490: }
491: break;
1.48 paf 492:
1.10 paf 493: case LS_DEF_COMMENT:
494: if(c=='\n') {
495: pop_LS(PC);
1.48 paf 496: RC;
1.37 paf 497: }
498: break;
499:
1.48 paf 500: case LS_DEF_SPECIAL_BODY:
1.37 paf 501: if(c=='\n') {
1.48 paf 502: switch(*PC->source) {
503: case '@': case 0: // end of special_code
1.37 paf 504: pop_LS(PC);
1.48 paf 505: break;
506: }
507: RC;
508: }
509: break;
510:
511: // (EXPRESSION)
512: case LS_EXPRESSION_BODY:
513: switch(c) {
514: case ')':
515: if(--lexical_brackets_nestage==0)
516: pop_LS(PC); //(EXPRESSION).
517: RC;
518: case '$':
519: push_LS(PC, LS_VAR_NAME_IN_EXPRESSION);
520: RC;
521: case '^':
522: push_LS(PC, LS_METHOD_NAME);
523: RC;
524: case '(':
525: lexical_brackets_nestage++;
526: RC;
527: case '+': case '-': case '*': case '/': case '%':
1.50 ! paf 528: RC;
1.49 paf 529: case '&': case '|':
1.50 ! paf 530: if(*PC->source==c) { // && ||
! 531: result=c=='&'?LOGICAL_AND:LOGICAL_OR;
! 532: PC->source++; PC->col++;
! 533: } else
! 534: result=c;
! 535: goto break2;
1.49 paf 536: case '<': case '>': case '=': case '!':
1.48 paf 537: case ';':
538: RC;
539: case '"':
540: push_LS(PC, LS_EXPRESSION_STRING);
541: RC;
1.50 ! paf 542: case 'l': case 'g': case 'e': case 'n':
! 543: if(end==begin) {
! 544: case(*PC->source) {
! 545: }
! 546: }
1.48 paf 547: break;
548: case ' ': case '\t': case '\n':
549: if(end!=begin) {
550: // append piece till whitespace
551: PC->string->APPEND(begin, end-begin, PC->file, begin_line);
552: }
553: // reset piece 'start' position & line
1.50 ! paf 554: begin=PC->source; // after whitespace
1.48 paf 555: begin_line=PC->line;
556: continue;
1.1 paf 557: }
558: break;
559:
1.10 paf 560: // VARIABLE GET/PUT/WITH
1.1 paf 561: case LS_VAR_NAME_SIMPLE:
1.48 paf 562: case LS_VAR_NAME_IN_EXPRESSION:
563: if(PC->ls==LS_VAR_NAME_IN_EXPRESSION) {
564: // name in expression ends also before binary operators
565: switch(c) {
566: case '+': case '-': case '*': case '/': case '%':
567: case '&': case '|':
568: case '<': case '>': case '=': case '!':
569: pop_LS(PC);
570: PC->source--; if(--PC->col<0) { PC->line--; PC->col=-1; }
571: result=EON;
572: goto break2;
573: }
574: }
575: switch(c) {
576: case 0:
577: case ' ': case '\t': case '\n':
578: case ';':
579: case ']': case '}':
1.1 paf 580: pop_LS(PC);
1.32 paf 581: PC->source--; if(--PC->col<0) { PC->line--; PC->col=-1; }
1.13 paf 582: result=EON;
1.1 paf 583: goto break2;
1.48 paf 584: case '[':
585: PC->ls=LS_VAR_SQUARE;
1.1 paf 586: lexical_brackets_nestage=1;
1.48 paf 587: RC;
588: case '{':
589: if(begin==end) { // ${name}, no need of EON, switching LS
590: PC->ls=LS_VAR_NAME_CURLY;
591: } else {
592: PC->ls=LS_VAR_CURLY;
593: lexical_brackets_nestage=1;
594: }
595:
596: RC;
597: case '(':
598: PC->ls=LS_EXPRESSION_BODY;
1.1 paf 599: lexical_brackets_nestage=1;
1.48 paf 600: RC;
601: case '.': // name part delim
602: case '$': // name part subvar
603: case ':': // ':name' or 'class:name'
604: RC;
1.1 paf 605: }
606: break;
1.48 paf 607:
1.1 paf 608: case LS_VAR_NAME_CURLY:
1.48 paf 609: switch(c) {
610: case '}': // ${name} finished, restoring LS
1.1 paf 611: pop_LS(PC);
1.48 paf 612: RC;
613: case '.': // name part delim
614: case '$': // name part subvar
615: case ':': // ':name' or 'class:name'
616: RC;
1.1 paf 617: }
618: break;
1.48 paf 619:
620: case LS_VAR_SQUARE:
621: switch(c) {
622: case '$':
1.10 paf 623: push_LS(PC, LS_VAR_NAME_SIMPLE);
1.48 paf 624: RC;
625: case '^':
1.10 paf 626: push_LS(PC, LS_METHOD_NAME);
1.48 paf 627: RC;
628: case ']':
1.1 paf 629: if(--lexical_brackets_nestage==0) {
630: pop_LS(PC);
1.48 paf 631: RC;
1.1 paf 632: }
1.48 paf 633: break;
634: case ';': // operator_or_fmt;value delim
635: RC;
636: case '[':
637: lexical_brackets_nestage++;
638: break;
1.1 paf 639: }
640: break;
1.48 paf 641:
1.1 paf 642: case LS_VAR_CURLY:
1.48 paf 643: switch(c) {
644: case '$':
1.10 paf 645: push_LS(PC, LS_VAR_NAME_SIMPLE);
1.48 paf 646: RC;
647: case '^':
1.10 paf 648: push_LS(PC, LS_METHOD_NAME);
1.48 paf 649: RC;
650: case '}':
1.1 paf 651: if(--lexical_brackets_nestage==0) {
652: pop_LS(PC);
1.48 paf 653: RC;
1.1 paf 654: }
1.48 paf 655: break;
656: case '{':
1.1 paf 657: lexical_brackets_nestage++;
1.48 paf 658: break;
659: }
1.1 paf 660: break;
661:
1.10 paf 662: // METHOD CALL
1.1 paf 663: case LS_METHOD_NAME:
1.48 paf 664: switch(c) {
665: case '[':
666: PC->ls=LS_METHOD_SQUARE;
1.1 paf 667: lexical_brackets_nestage=1;
1.48 paf 668: RC;
669: case '{':
1.1 paf 670: PC->ls=LS_METHOD_CURLY;
671: lexical_brackets_nestage=1;
1.48 paf 672: RC;
673: case '.': // name part delim
674: case '$': // name part subvar
675: case ':': // ':name' or 'class:name'
676: RC;
1.1 paf 677: }
678: break;
1.48 paf 679:
680: case LS_METHOD_SQUARE:
681: switch(c) {
682: case '$':
1.10 paf 683: push_LS(PC, LS_VAR_NAME_SIMPLE);
1.48 paf 684: RC;
685: case '^':
1.10 paf 686: push_LS(PC, LS_METHOD_NAME);
1.48 paf 687: RC;
688: case ';': // param delim
689: RC;
690: case ']':
1.1 paf 691: if(--lexical_brackets_nestage==0) {
692: PC->ls=LS_METHOD_AFTER;
1.48 paf 693: RC;
1.1 paf 694: }
1.48 paf 695: break;
696: case '[':
1.1 paf 697: lexical_brackets_nestage++;
1.48 paf 698: break;
699: }
1.1 paf 700: break;
1.48 paf 701:
1.1 paf 702: case LS_METHOD_CURLY:
1.48 paf 703: switch(c) {
704: case '$':
1.10 paf 705: push_LS(PC, LS_VAR_NAME_SIMPLE);
1.48 paf 706: RC;
707: case '^':
1.10 paf 708: push_LS(PC, LS_METHOD_NAME);
1.48 paf 709: RC;
710: case '}':
1.1 paf 711: if(--lexical_brackets_nestage==0) {
712: PC->ls=LS_METHOD_AFTER;
1.48 paf 713: RC;
1.1 paf 714: }
1.48 paf 715: break;
716: case '{':
1.1 paf 717: lexical_brackets_nestage++;
1.48 paf 718: break;
719: }
1.1 paf 720: break;
1.48 paf 721:
1.1 paf 722: case LS_METHOD_AFTER:
1.47 paf 723: if(c=='[') {/* )( }( */
1.48 paf 724: PC->ls=LS_METHOD_SQUARE;
1.1 paf 725: lexical_brackets_nestage=1;
1.48 paf 726: RC;
1.1 paf 727: }
728: if(c=='{') {/* ){ }{ */
729: PC->ls=LS_METHOD_CURLY;
730: lexical_brackets_nestage=1;
1.48 paf 731: RC;
1.1 paf 732: }
733: pop_LS(PC);
1.32 paf 734: PC->source--; if(--PC->col<0) { PC->line--; PC->col=-1; }
1.13 paf 735: result=EON;
1.1 paf 736: goto break2;
737: }
1.9 paf 738: if(c==0) {
1.1 paf 739: result=-1;
740: break;
741: }
742: }
743:
744: break2:
1.9 paf 745: if(begin==end)
1.1 paf 746: return result;
747: else {
748: PC->pending_state=result;
1.10 paf 749: // strip last \n before LS_DEF_NAME or EOF
750: if((c=='@' || c==0) && end[-1]=='\n')
751: end--;
1.30 paf 752: if(end!=begin) {
753: // append last piece
754: PC->string->APPEND(begin, end-begin, PC->file, begin_line/*, start_col*/);
755: }
1.17 paf 756: // create STRING value: array of OP_VALUE+vstring
1.45 paf 757: *lvalp=SL(NEW VString(*PC->string));
1.10 paf 758: // new pieces storage
1.25 paf 759: PC->string=NEW String(POOL);
1.10 paf 760: // go!
1.4 paf 761: return STRING;
1.1 paf 762: }
763: }
764:
1.9 paf 765: int real_yyerror(parse_control *pc, char *s) /* Called by yyparse on error */
1.1 paf 766: {
1.16 paf 767: //fprintf(stderr, "[%s]\n", s);
1.6 paf 768:
1.46 paf 769: strncpy(pc->error, s, MAX_STRING); // TODO: перепроверить с треклятым последним байтом
1.1 paf 770: return 1;
771: }
772:
773: static void
1.9 paf 774: yyprint(
1.1 paf 775: FILE *file,
776: int type,
777: YYSTYPE value)
778: {
1.9 paf 779: if(type==STRING)
1.38 paf 780: fprintf(file, " \"%s\"", SLA2S(value)->cstr());
1.1 paf 781: }
782:
E-mail: