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