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

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

E-mail: