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

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

E-mail: