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