Annotation of parser3/src/main/compile.y, revision 1.32

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

E-mail: