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

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

E-mail: