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

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

E-mail: