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

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

E-mail: