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