Annotation of parser3/src/main/compile.y, revision 1.40
1.24 paf 1: /*
1.40 ! paf 2: $Id: compile.y,v 1.39 2001/02/25 08:50:13 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) {
261: strcpy(PC->error, name.cstr());
262: strcat(PC->error, ": undefined class in call");
263: YYERROR;
264: }
265: $$=CL(vclass);
266: P($$, $3);
267: };
268:
1.9 paf 269: store_params: store_param | store_params store_param { $$=$1; P($$, $2) };
1.1 paf 270: store_param: store_round_param | store_curly_param;
271: store_round_param: '(' store_param_parts ')' {$$=$2};
1.31 paf 272: store_param_parts:
1.32 paf 273: store_param_part
274: | store_param_parts ';' store_param_part { $$=$1; P($$, $3) }
1.31 paf 275: ;
1.10 paf 276: store_curly_param: '{' maybe_codes '}' {
1.25 paf 277: $$=N(POOL);
1.29 paf 278: PCA($$, $2);
1.9 paf 279: OP($$, OP_STORE_PARAM);
1.1 paf 280: };
1.32 paf 281: store_param_part:
1.33 paf 282: empty /* optimized () case */
283: | STRING { /* optimized (STRING) case */
1.32 paf 284: $$=$1;
285: OP($$, OP_STORE_PARAM);
286: }
1.33 paf 287: | complex_constructor_param_value { /* (something complex) */
1.32 paf 288: $$=$1;
289: OP($$, OP_STORE_PARAM);
290: }
291: ;
1.1 paf 292:
293: /* name */
294:
1.20 paf 295: name_expr_dive_code: name_expr_value | name_path name_expr_value { $$=$1; P($$, $2) };
1.1 paf 296:
1.9 paf 297: name_path: name_step | name_path name_step { $$=$1; P($$, $2) };
1.1 paf 298: name_step: name_advance1 '.';
299: name_advance1: name_expr_value {
300: /* stack: context */
301: $$=$1; /* stack: context,name */
1.9 paf 302: OP($$, OP_GET_ELEMENT); /* name=pop; context=pop; stack: context.get_element(name) */
1.1 paf 303: };
304: name_advance2: name_expr_value {
305: /* stack: context */
306: $$=$1; /* stack: context,name */
1.9 paf 307: OP($$, OP_GET_ELEMENT); /* name=pop; context=pop; stack: context.get_element(name) */
1.1 paf 308: }
1.4 paf 309: | STRING BOGUS
1.1 paf 310: ;
311: name_expr_value:
1.4 paf 312: STRING /* subname_is_const */
1.1 paf 313: | name_expr_subvar_value /* $subname_is_var_value */
314: | name_expr_with_subvar_value /* xxx$part_of_subname_is_var_value[$...] */
315: ;
316: name_expr_subvar_value: '$' subvar_ref_name_rdive {
317: $$=$2;
1.9 paf 318: OP($$, OP_GET_ELEMENT);
1.1 paf 319: };
1.4 paf 320: name_expr_with_subvar_value: STRING subvar_get_writes {
1.25 paf 321: $$=N(POOL);
1.3 paf 322: OP($$, OP_CREATE_EWPOOL);
1.9 paf 323: P($$, $1);
1.17 paf 324: OP($$, OP_WRITE);
1.9 paf 325: P($$, $2);
326: OP($$, OP_REDUCE_EWPOOL);
1.1 paf 327: };
1.18 paf 328: subvar_ref_name_rdive: subvar_ref_name_rdive_read | subvar_ref_name_rdive_root;
329: subvar_ref_name_rdive_read: STRING {
1.25 paf 330: $$=N(POOL);
1.18 paf 331: OP($$, OP_WITH_READ);
1.9 paf 332: P($$, $1);
1.1 paf 333: };
1.18 paf 334: subvar_ref_name_rdive_root: ':' STRING {
1.25 paf 335: $$=N(POOL);
1.18 paf 336: OP($$, OP_WITH_ROOT);
337: P($$, $2);
338: };
1.9 paf 339: subvar_get_writes: subvar__get_write | subvar_get_writes subvar__get_write { $$=$1; P($$, $2) };
1.1 paf 340: subvar__get_write: '$' subvar_ref_name_rdive {
341: $$=$2;
1.17 paf 342: OP($$, OP_GET_ELEMENT__WRITE);
1.1 paf 343: };
344:
345:
346: /* with */
347:
348: with: '$' name_without_curly_rdive '{' codes '}' {
349: $$=$2;
1.9 paf 350: OP($$, OP_CREATE_RWPOOL);
351: P($$, $4);
352: OP($$, OP_REDUCE_RWPOOL);
1.17 paf 353: OP($$, OP_WRITE);
1.1 paf 354: };
355:
1.27 paf 356: /* basics */
1.1 paf 357:
1.4 paf 358: write_str_literal: STRING {
1.38 paf 359: if(SLA2S($1)->size()) {
1.30 paf 360: $$=$1;
361: OP($$, OP_WRITE);
362: } else {
363: // optimized case of special end of macro. see yylex
364: $$=N(POOL);
365: }
1.26 paf 366: };
1.38 paf 367: empty_value: /* empty */ { $$=SL(NEW VString(POOL)) };
1.25 paf 368: empty: /* empty */ { $$=N(POOL) };
1.1 paf 369:
370: %%
371:
372: /*
373: 000$111(2222)00
374: 000$111{3333}00
1.9 paf 375: $,^: push,=0
1.1 paf 376: 1:( { break=pop
377: 2:( ) pop
378: 3:{ } pop
379:
380: 000^111(2222)4444{33333}4000
1.9 paf 381: $,^: push,=0
1.1 paf 382: 1:( { break=pop
383: 2:( )=4
384: 3:{ }=4
385: 4:[^({]=pop
386: */
387:
388: int yylex(YYSTYPE *lvalp, void *pc) {
389: #define lexical_brackets_nestage PC->brackets_nestages[PC->sp]
390:
391: register int c;
392: int result;
393:
394: if(PC->pending_state) {
395: result=PC->pending_state;
396: PC->pending_state=0;
397: return result;
398: }
399:
1.9 paf 400: char *begin=PC->source;
401: char *end;
402: int begin_line=PC->line;
1.1 paf 403: while(1) {
1.9 paf 404: c=*(end=(PC->source++));
1.1 paf 405:
1.4 paf 406: if(c=='\n') {
1.1 paf 407: PC->line++;
1.8 paf 408: PC->col=0;
1.10 paf 409: } else
1.4 paf 410: PC->col++;
1.1 paf 411:
1.40 ! paf 412: // escaping: ^^ ^$ ^; ^) ^} ^( ^{
1.1 paf 413: if(c=='^') {
1.40 ! paf 414: char next_c=*PC->source;
1.1 paf 415:
1.40 ! paf 416: if(next_c=='^' || next_c=='$' || next_c==';' ||
! 417: next_c=='(' || next_c==')' ||
! 418: next_c=='{' || next_c=='}') {
! 419: if(end!=begin) {
! 420: // append piece till ^
! 421: PC->string->APPEND(begin, end-begin, PC->file, begin_line);
! 422: }
! 423: // reset piece 'start' position & line
! 424: begin=PC->source; // ^
1.9 paf 425: begin_line=PC->line;
1.40 ! paf 426: // skip over ^ and _
! 427: PC->source++;
! 428: // skip analysis = forced literal
1.1 paf 429: continue;
430: }
431: }
432: switch(PC->ls) {
1.10 paf 433:
434: // USER'S = NOT OURS
1.1 paf 435: case LS_USER:
436: if(c=='$') {
1.10 paf 437: push_LS(PC, LS_VAR_NAME_SIMPLE);
1.1 paf 438: result=c;
439: goto break2;
440: }
441: if(c=='^') {
1.10 paf 442: push_LS(PC, LS_METHOD_NAME);
443: result=c;
444: goto break2;
445: }
446: if(c=='@' && PC->col==0+1) {
1.1 paf 447: result=c;
1.10 paf 448: push_LS(PC, LS_DEF_NAME);
449: goto break2;
450: }
451:
452: break;
453:
454: // METHOD DEFINITION
455: case LS_DEF_NAME:
456: if(c=='[') {
457: result=c;
458: PC->ls=LS_DEF_PARAMS;
459: goto break2;
460: }
1.37 paf 461: if(c=='\n') {
1.10 paf 462: result=c;
1.37 paf 463: PC->ls=LS_SPEC_CODE;
1.10 paf 464: goto break2;
465: }
466: break;
467: case LS_DEF_PARAMS:
468: if(c==';') {
469: result=c;
470: goto break2;
471: }
472: if(c==']') {
473: result=c;
474: PC->ls=*PC->source=='['?LS_DEF_LOCALS:LS_DEF_COMMENT;
475: goto break2;
476: }
477: if(c=='\n') { // wrong. bailing out
478: result=c;
479: pop_LS(PC);
480: goto break2;
481: }
482: break;
483: case LS_DEF_LOCALS:
484: if(c=='[' || c==';') {
485: result=c;
486: goto break2;
487: }
488: if(c==']') {
489: result=c;
490: PC->ls=LS_DEF_COMMENT;
491: goto break2;
492: }
493: if(c=='\n') { // wrong. bailing out
494: result=c;
495: pop_LS(PC);
496: goto break2;
497: }
498: break;
499: case LS_DEF_COMMENT:
500: if(c=='\n') {
501: result=c;
502: pop_LS(PC);
1.37 paf 503: goto break2;
504: }
505: break;
506:
507: case LS_SPEC_CODE:
508: if(c=='\n') {
509: result=c;
510: if(*PC->source=='@' || *PC->source==0) // end of special_code
511: pop_LS(PC);
1.1 paf 512: goto break2;
513: }
514: break;
515:
1.10 paf 516: // VARIABLE GET/PUT/WITH
1.1 paf 517: case LS_VAR_NAME_SIMPLE:
518: if(c==0 ||
519: c==' '|| c=='\t' || c=='\n' ||
520: c==')' || c=='}') {
521: pop_LS(PC);
1.32 paf 522: PC->source--; if(--PC->col<0) { PC->line--; PC->col=-1; }
1.13 paf 523: result=EON;
1.1 paf 524: goto break2;
525: }
1.13 paf 526: if(begin==end && c=='{') { /* ${name}, no need of EON, switching LS */
1.1 paf 527: PC->ls=LS_VAR_NAME_CURLY;
528: result=c;
529: goto break2;
530: }
531: if(c=='(') {
532: PC->ls=LS_VAR_ROUND;
533: lexical_brackets_nestage=1;
534: result=c;
535: goto break2;
536: }
537: if(c=='{') {
538: PC->ls=LS_VAR_CURLY;
539: lexical_brackets_nestage=1;
540: result=c;
541: goto break2;
542: }
1.39 paf 543: if(c=='.'/* name part delim */ ||
544: c=='$'/* name part subvar */ ||
545: c==':'/* ':name' or 'class:name' */) {
1.1 paf 546: result=c;
547: goto break2;
548: }
549: break;
550: case LS_VAR_NAME_CURLY:
551: if(c=='}') { /* ${name} finished, restoring LS */
552: pop_LS(PC);
553: result=c;
554: goto break2;
555: }
1.39 paf 556: if(c=='.'/* name part delim */ ||
557: c=='$'/*name part subvar*/ ||
558: c==':'/* ':name' or 'class:name' */) {
1.1 paf 559: result=c;
560: goto break2;
561: }
562: break;
563: case LS_VAR_ROUND:
564: if(c=='$') {
1.10 paf 565: push_LS(PC, LS_VAR_NAME_SIMPLE);
1.1 paf 566: result=c;
567: goto break2;
568: }
569: if(c=='^') {
1.10 paf 570: push_LS(PC, LS_METHOD_NAME);
1.1 paf 571: result=c;
572: goto break2;
573: }
574: if(c==')') {
575: if(--lexical_brackets_nestage==0) {
576: pop_LS(PC);
577: result=c;
578: goto break2;
579: }
580: }
581: if(c==';'/* operator_or_fmt;value delim */) {
582: result=c;
583: goto break2;
584: }
585: if(c=='(')
586: lexical_brackets_nestage++;
587: break;
588: case LS_VAR_CURLY:
589: if(c=='$') {
1.10 paf 590: push_LS(PC, LS_VAR_NAME_SIMPLE);
1.1 paf 591: result=c;
592: goto break2;
593: }
594: if(c=='^') {
1.10 paf 595: push_LS(PC, LS_METHOD_NAME);
1.1 paf 596: result=c;
597: goto break2;
598: }
599: if(c=='}')
600: if(--lexical_brackets_nestage==0) {
601: pop_LS(PC);
602: result=c;
603: goto break2;
604: }
605: if(c=='{')
606: lexical_brackets_nestage++;
607: break;
608:
1.10 paf 609: // METHOD CALL
1.1 paf 610: case LS_METHOD_NAME:
611: if(c=='(') {
612: PC->ls=LS_METHOD_ROUND;
613: lexical_brackets_nestage=1;
614: result=c;
615: goto break2;
616: }
617: if(c=='{') {
618: PC->ls=LS_METHOD_CURLY;
619: lexical_brackets_nestage=1;
620: result=c;
621: goto break2;
622: }
1.39 paf 623: if(c=='.'/* name part delim */ ||
624: c=='$'/* name part subvar */ ||
625: c==':'/* ':name' or 'class:name' */) {
1.1 paf 626: result=c;
627: goto break2;
628: }
629: break;
630: case LS_METHOD_ROUND:
631: if(c=='$') {
1.10 paf 632: push_LS(PC, LS_VAR_NAME_SIMPLE);
1.1 paf 633: result=c;
634: goto break2;
635: }
636: if(c=='^') {
1.10 paf 637: push_LS(PC, LS_METHOD_NAME);
1.1 paf 638: result=c;
639: goto break2;
640: }
641: if(c==';'/* param delim */) {
642: result=c;
643: goto break2;
644: }
645: if(c==')')
646: if(--lexical_brackets_nestage==0) {
647: PC->ls=LS_METHOD_AFTER;
648: result=c;
649: goto break2;
650: }
651: if(c=='(')
652: lexical_brackets_nestage++;
653: break;
654: case LS_METHOD_CURLY:
655: if(c=='$') {
1.10 paf 656: push_LS(PC, LS_VAR_NAME_SIMPLE);
1.1 paf 657: result=c;
658: goto break2;
659: }
660: if(c=='^') {
1.10 paf 661: push_LS(PC, LS_METHOD_NAME);
1.1 paf 662: result=c;
663: goto break2;
664: }
665: if(c=='}')
666: if(--lexical_brackets_nestage==0) {
667: PC->ls=LS_METHOD_AFTER;
668: result=c;
669: goto break2;
670: }
671: if(c=='{')
672: lexical_brackets_nestage++;
673: break;
674: case LS_METHOD_AFTER:
675: if(c=='(') {/* )( }( */
676: PC->ls=LS_METHOD_ROUND;
677: lexical_brackets_nestage=1;
678: result=c;
679: goto break2;
680: }
681: if(c=='{') {/* ){ }{ */
682: PC->ls=LS_METHOD_CURLY;
683: lexical_brackets_nestage=1;
684: result=c;
685: goto break2;
686: }
687: pop_LS(PC);
1.32 paf 688: PC->source--; if(--PC->col<0) { PC->line--; PC->col=-1; }
1.13 paf 689: result=EON;
1.1 paf 690: goto break2;
691: }
1.9 paf 692: if(c==0) {
1.1 paf 693: result=-1;
694: break;
695: }
696: }
697:
698: break2:
1.9 paf 699: if(begin==end)
1.1 paf 700: return result;
701: else {
702: PC->pending_state=result;
1.10 paf 703: // strip last \n before LS_DEF_NAME or EOF
704: if((c=='@' || c==0) && end[-1]=='\n')
705: end--;
1.30 paf 706: if(end!=begin) {
707: // append last piece
708: PC->string->APPEND(begin, end-begin, PC->file, begin_line/*, start_col*/);
709: }
1.17 paf 710: // create STRING value: array of OP_VALUE+vstring
1.38 paf 711: *lvalp=SL(NEW VString(PC->string));
1.10 paf 712: // new pieces storage
1.25 paf 713: PC->string=NEW String(POOL);
1.10 paf 714: // go!
1.4 paf 715: return STRING;
1.1 paf 716: }
717: }
718:
1.9 paf 719: int real_yyerror(parse_control *pc, char *s) /* Called by yyparse on error */
1.1 paf 720: {
1.16 paf 721: //fprintf(stderr, "[%s]\n", s);
1.6 paf 722:
723: s[MAX_STRING-1]=0; strcpy(pc->error, s);
1.1 paf 724: return 1;
725: }
726:
727: static void
1.9 paf 728: yyprint(
1.1 paf 729: FILE *file,
730: int type,
731: YYSTYPE value)
732: {
1.9 paf 733: if(type==STRING)
1.38 paf 734: fprintf(file, " \"%s\"", SLA2S(value)->cstr());
1.1 paf 735: }
736:
E-mail: