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

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

E-mail: