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

1.105     paf         1: /** @file
1.106     paf         2:        Parser: compiler(lexical parser and grammar).
                      3: 
1.87      paf         4:        Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.106     paf         5: 
1.89      paf         6:        Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
1.87      paf         7: 
1.128   ! paf         8:        $Id: compile.y,v 1.127 2001/04/25 11:02:56 paf Exp $
1.88      paf         9: */
                     10: 
1.106     paf        11: /**
                     12:        @todo parser4: 
                     13:        - cache compiled code from request to request. to do that...
                     14:                -#:     make method definitions, @CLASS, @BASE, @USE instructions,
1.88      paf        15:                        which would be executed afterwards, and actions
                     16:                        now performed at compile time would be delayed to run time.
1.106     paf        17:                -#:     make cache expiration on time and on disk-change of class source
                     18:                -#:     in apache use subpools for compiled class storage
                     19:                -#:     in iis make up specialized Pool object for that
1.24      paf        20: */
                     21: 
1.1       paf        22: %{
1.90      paf        23: #define YYSTYPE  Array/*<Operation>*/ *
1.9       paf        24: #define YYPARSE_PARAM  pc
                     25: #define YYLEX_PARAM  pc
                     26: #define YYDEBUG  1
1.106     paf        27: #define YYERROR_VERBOSE        1
1.9       paf        28: #define yyerror(msg)  real_yyerror((parse_control *)pc, msg)
                     29: #define YYPRINT(file, type, value)  yyprint(file, type, value)
1.1       paf        30: 
1.108     paf        31: #include "pa_config_includes.h"
1.1       paf        32: #include <stdio.h>
                     33: #include <stdlib.h>
1.117     paf        34: #include <ctype.h>
1.1       paf        35: 
                     36: #include "compile_tools.h"
1.8       paf        37: #include "pa_value.h"
1.12      paf        38: #include "pa_request.h"
1.39      paf        39: #include "pa_vobject.h"
1.52      paf        40: #include "pa_vdouble.h"
1.98      paf        41: #include "pa_globals.h"
1.120     paf        42: #include "pa_vunknown.h"
1.39      paf        43: 
1.85      paf        44: #define SELF_ELEMENT_NAME "self"
1.97      paf        45: #define USE_CONTROL_METHOD_NAME "USE"
1.1       paf        46: 
1.125     paf        47: static int real_yyerror(parse_control *pc, char *s);
1.9       paf        48: static void yyprint(FILE *file, int type, YYSTYPE value);
1.125     paf        49: static int yylex(YYSTYPE *lvalp, void *pc);
1.1       paf        50: 
                     51: 
1.8       paf        52: // local convinient inplace typecast & var
1.114     paf        53: #define PC  (*(parse_control *)pc)
                     54: #define POOL  (*PC.pool)
1.25      paf        55: #undef NEW
                     56: #define NEW new(POOL)
1.107     paf        57: #ifndef DOXYGEN
1.1       paf        58: %}
                     59: 
                     60: %pure_parser
                     61: 
1.13      paf        62: %token EON
1.4       paf        63: %token STRING
1.1       paf        64: %token BOGUS
1.55      paf        65: 
1.58      paf        66: %token BAD_STRING_COMPARISON_OPERATOR
1.114     paf        67: %token BAD_HEX_LITERAL
1.58      paf        68: 
1.59      paf        69: %token LAND "&&"
1.58      paf        70: %token LOR "||"
1.59      paf        71: %token LXOR "##"
1.58      paf        72: 
                     73: %token NLE "<="
                     74: %token NGE ">="
                     75: %token NEQ "=="
                     76: %token NNE "!="
                     77: 
                     78: %token SLT "lt"
                     79: %token SGT "gt"
                     80: %token SLE "le"
                     81: %token SGE "ge"
                     82: %token SEQ "eq"
                     83: %token SNE "ne"
                     84: 
1.67      paf        85: %token DEF "def"
                     86: %token IN "in"
                     87: %token FEXISTS "-f"
1.127     paf        88: %token DEXISTS "-d"
1.95      paf        89: %token IS "is"
1.67      paf        90: 
1.57      paf        91: /* logical */
1.95      paf        92: %left "is"
1.61      paf        93: %left "lt" "gt" "le" "ge"
                     94: %left "eq" "ne"
1.59      paf        95: %left '<' '>' "<=" ">=" "##"
1.57      paf        96: %left "==" "!="
                     97: %left "||"
                     98: %left "&&"
1.127     paf        99: %left "def" "in" "-f" "-d"
1.68      paf       100: %left '!'
1.57      paf       101: 
                    102: /* bitwise */
1.59      paf       103: %left '#'
1.57      paf       104: %left '&' '|'
1.68      paf       105: %left '~'
1.57      paf       106: 
1.56      paf       107: /* numerical */
1.55      paf       108: %left '-' '+'
1.57      paf       109: %left '*' '/' '%'
1.56      paf       110: %left NEG     /* negation: unary - */
1.1       paf       111: 
                    112: %%
1.88      paf       113: all:
1.10      paf       114:        one_big_piece {
1.75      paf       115:        Method& method=*NEW Method(POOL, 
1.85      paf       116:                *main_method_name, 
1.122     paf       117:                Method::CT_ANY,
1.81      paf       118:                0, 0, /*min, max numbered_params_count*/
1.75      paf       119:                0/*param_names*/, 0/*local_names*/, 
                    120:                $1/*parser_code*/, 0/*native_code*/);
1.114     paf       121:        PC.cclass->add_method(*main_method_name, method);
1.10      paf       122: }
                    123: |      methods;
                    124: 
                    125: methods: method | methods method;
                    126: one_big_piece: maybe_codes;
                    127: 
1.34      paf       128: method: control_method | code_method;
                    129: 
                    130: control_method: '@' STRING '\n' 
                    131:                                control_strings {
1.120     paf       132:        const String& command=*LA2S($2);
1.34      paf       133:        YYSTYPE strings_code=$4;
1.37      paf       134:        if(strings_code->size()<1*2) {
1.114     paf       135:                strcpy(PC.error, "@");
                    136:                strcat(PC.error, command.cstr());
                    137:                strcat(PC.error, " is empty");
1.37      paf       138:                YYERROR;
                    139:        }
1.74      paf       140:        if(command==CLASS_NAME) {
1.128   ! paf       141:                if(PC.cclass!=&PC.request->OP) { // already changed from default[OP]?
1.114     paf       142:                        strcpy(PC.error, "class already have a name '");
                    143:                        strncat(PC.error, PC.cclass->name().cstr(), 100);
                    144:                        strcat(PC.error, "'");
1.73      paf       145:                        YYERROR;
                    146:                }
                    147:                if(strings_code->size()==1*2) {
                    148:                        // new class' name
1.120     paf       149:                        const String *name=LA2S(strings_code);
1.73      paf       150:                        // creating the class
1.114     paf       151:                        PC.cclass=NEW VClass(POOL);
                    152:                        PC.cclass->set_name(*name);
1.73      paf       153:                        // append to request's classes
1.114     paf       154:                        PC.request->classes().put(*name, PC.cclass);
1.73      paf       155:                } else {
1.114     paf       156:                        strcpy(PC.error, "@"CLASS_NAME" must contain sole name");
1.34      paf       157:                        YYERROR;
                    158:                }
                    159:        } else {
1.85      paf       160:                if(command==USE_CONTROL_METHOD_NAME) {
1.109     paf       161:                        for(int i=0; i<strings_code->size(); i+=2) 
1.114     paf       162:                                PC.request->use_file(
1.120     paf       163:                                        PC.request->absolute(*LA2S(strings_code, i)));
1.74      paf       164:                } else if(command==BASE_NAME) {
1.124     paf       165:                        if(PC.cclass->base()) { // already changed from default?
1.114     paf       166:                                strcpy(PC.error, "class already have a base '");
                    167:                                strncat(PC.error, PC.cclass->base()->name().cstr(), 100);
                    168:                                strcat(PC.error, "'");
1.73      paf       169:                                YYERROR;
                    170:                        }
1.45      paf       171:                        if(strings_code->size()==1*2) {
1.120     paf       172:                                const String& base_name=*LA2S(strings_code);
1.45      paf       173:                                VClass *base=static_cast<VClass *>(
1.114     paf       174:                                        PC.request->classes().get(base_name));
1.45      paf       175:                                if(!base) {
1.114     paf       176:                                        strcpy(PC.error, base_name.cstr());
                    177:                                        strcat(PC.error, ": undefined class in @"BASE_NAME);
1.109     paf       178:                                        YYERROR;
                    179:                                }
                    180:                                // @CLASS == @BASE sanity check
1.114     paf       181:                                if(PC.cclass==base) {
                    182:                                        strcpy(PC.error, "@"CLASS_NAME" equals @"BASE_NAME);
1.34      paf       183:                                        YYERROR;
                    184:                                }
1.114     paf       185:                                PC.cclass->set_base(*base);
1.45      paf       186:                        } else {
1.114     paf       187:                                strcpy(PC.error, "@"BASE_NAME" must contain sole name");
1.45      paf       188:                                YYERROR;
1.34      paf       189:                        }
                    190:                } else {
1.114     paf       191:                        strcpy(PC.error, "'");
                    192:                        strncat(PC.error, command.cstr(), MAX_STRING/2);
                    193:                        strcat(PC.error, "' invalid special name. valid names are "
1.92      paf       194:                                "'"CLASS_NAME"', '"USE_CONTROL_METHOD_NAME"' and '"BASE_NAME"'");
1.34      paf       195:                        YYERROR;
                    196:                }
                    197:        }
                    198: };
1.37      paf       199: control_strings: control_string | control_strings control_string { $$=$1; P($$, $2) };
                    200: control_string: maybe_string '\n';
                    201: maybe_string: empty | STRING;
1.34      paf       202: 
                    203: code_method: '@' STRING bracketed_maybe_strings maybe_bracketed_strings maybe_comment '\n' 
1.10      paf       204:                        maybe_codes {
1.120     paf       205:        const String *name=LA2S($2);
1.10      paf       206: 
                    207:        YYSTYPE params_names_code=$3;
1.75      paf       208:        Array *params_names=0;
                    209:        if(int size=params_names_code->size()) {
                    210:                params_names=NEW Array(POOL);
                    211:                for(int i=0; i<size; i+=2)
1.120     paf       212:                        *params_names+=LA2S(params_names_code, i);
1.75      paf       213:        }
1.10      paf       214: 
                    215:        YYSTYPE locals_names_code=$4;
1.75      paf       216:        Array *locals_names=0;
                    217:        if(int size=locals_names_code->size()) {
                    218:                locals_names=NEW Array(POOL);
                    219:                for(int i=0; i<size; i+=2)
1.120     paf       220:                        *locals_names+=LA2S(locals_names_code, i);
1.75      paf       221:        }
1.10      paf       222: 
1.76      paf       223:        Method& method=*NEW Method(POOL, 
                    224:                *name, 
1.122     paf       225:                Method::CT_ANY,
1.81      paf       226:                0, 0/*min,max numbered_params_count*/, 
1.76      paf       227:                params_names, locals_names, 
                    228:                $7, 0);
1.114     paf       229:        PC.cclass->add_method(*name, method);
1.8       paf       230: };
1.10      paf       231: 
                    232: maybe_bracketed_strings: empty | bracketed_maybe_strings;
                    233: bracketed_maybe_strings: '[' maybe_strings ']' {$$=$2};
                    234: maybe_strings: empty | strings;
                    235: strings: STRING | strings ';' STRING { $$=$1; P($$, $3) };
                    236: 
                    237: maybe_comment: empty | STRING;
1.1       paf       238: 
                    239: /* codes */
                    240: 
1.10      paf       241: maybe_codes: empty | codes;
                    242: 
1.90      paf       243: codes: code | codes code { $$=$1; P($$, $2) };
1.81      paf       244: code: write_string | action;
1.1       paf       245: action: get | put | with | call;
                    246: 
                    247: /* get */
                    248: 
1.64      paf       249: get: get_value {
                    250:        $$=$1; /* stack: resulting value */
1.102     paf       251:        O($$, OP_WRITE_VALUE); /* value=pop; wcontext.write(value) */
1.1       paf       252: };
1.64      paf       253: get_value: '$' get_name_value { $$=$2 }
                    254: get_name_value: name_without_curly_rdive EON | name_in_curly_rdive;
1.1       paf       255: name_in_curly_rdive: '{' name_without_curly_rdive '}' { $$=$2 };
1.44      paf       256: name_without_curly_rdive: 
                    257:        name_without_curly_rdive_read 
                    258: |      name_without_curly_rdive_root
                    259: |      name_without_curly_rdive_class;
1.19      paf       260: name_without_curly_rdive_read: name_without_curly_rdive_code {
1.25      paf       261:        $$=N(POOL); 
1.22      paf       262:        Array *diving_code=$1;
1.120     paf       263:        const String *first_name=LA2S(diving_code);
1.85      paf       264:        if(first_name && *first_name==SELF_ELEMENT_NAME) {
1.54      paf       265:                O($$, OP_WITH_SELF); /* stack: starting context */
1.22      paf       266:                P($$, diving_code, 
                    267:                        /* skip over... */
                    268:                        diving_code->size()>2?3/*OP_+string+get_element*/:2/*OP_+string*/);
                    269:        } else {
1.54      paf       270:                O($$, OP_WITH_READ); /* stack: starting context */
1.22      paf       271:                P($$, diving_code);
                    272:        }
                    273:        /* diving code; stack: current context */
1.1       paf       274: };
1.19      paf       275: name_without_curly_rdive_root: ':' name_without_curly_rdive_code {
1.25      paf       276:        $$=N(POOL); 
1.54      paf       277:        O($$, OP_WITH_ROOT); /* stack: starting context */
1.19      paf       278:        P($$, $2); /* diving code; stack: current context */
                    279: };
1.44      paf       280: name_without_curly_rdive_class: class_prefix name_without_curly_rdive_code { $$=$1; P($$, $2) };
1.19      paf       281: name_without_curly_rdive_code: name_advance2 | name_path name_advance2 { $$=$1; P($$, $2) };
1.1       paf       282: 
                    283: /* put */
                    284: 
1.81      paf       285: put: '$' name_expr_wdive construct {
1.20      paf       286:        $$=$2; /* stack: context,name */
1.52      paf       287:        P($$, $3); /* stack: context,name,constructor_value */
1.20      paf       288: };
1.44      paf       289: name_expr_wdive: 
                    290:        name_expr_wdive_write
                    291: |      name_expr_wdive_root
                    292: |      name_expr_wdive_class;
1.28      paf       293: name_expr_wdive_write: name_expr_dive_code {
1.44      paf       294:        $$=N(POOL);
1.23      paf       295:        Array *diving_code=$1;
1.120     paf       296:        const String *first_name=LA2S(diving_code);
1.85      paf       297:        if(first_name && *first_name==SELF_ELEMENT_NAME) {
1.54      paf       298:                O($$, OP_WITH_SELF); /* stack: starting context */
1.23      paf       299:                P($$, diving_code, 
                    300:                        /* skip over... */
                    301:                        diving_code->size()>2?3/*OP_+string+get_element*/:2/*OP_+string*/);
                    302:        } else {
1.54      paf       303:                O($$, OP_WITH_WRITE); /* stack: starting context */
1.23      paf       304:                P($$, diving_code);
                    305:        }
                    306:        /* diving code; stack: current context */
1.20      paf       307: };
1.28      paf       308: name_expr_wdive_root: ':' name_expr_dive_code {
1.25      paf       309:        $$=N(POOL); 
1.54      paf       310:        O($$, OP_WITH_ROOT); /* stack: starting context */
1.9       paf       311:        P($$, $2); /* diving code; stack: context,name */
1.1       paf       312: };
1.44      paf       313: name_expr_wdive_class: class_prefix name_expr_dive_code { $$=$1; P($$, $2) };
1.20      paf       314: 
1.81      paf       315: construct: construct_by_code | construct_by_expr;
                    316: construct_by_code: '[' any_constructor_code_value ']' {
                    317:        $$=$2; /* stack: context, name, value */
                    318:        O($$, OP_CONSTRUCT_VALUE); /* value=pop; name=pop; context=pop; construct(context,name,value) */
                    319: }
                    320: ;
1.90      paf       321: construct_by_expr: '(' expr_value ')' { 
1.81      paf       322:        $$=$2; /* stack: context, name, value */
                    323:        O($$, OP_CONSTRUCT_EXPR); /* value=pop; name=pop; context=pop; construct(context,name,value) */
                    324: }
1.52      paf       325: ;
1.55      paf       326: any_constructor_code_value: 
1.120     paf       327:        unknown_value /* optimized $var[] case */
1.52      paf       328: |      STRING /* optimized $var[STRING] case */
1.55      paf       329: |      constructor_code_value /* $var[something complex] */
1.1       paf       330: ;
1.55      paf       331: constructor_code_value: constructor_code {
1.25      paf       332:        $$=N(POOL); 
1.54      paf       333:        O($$, OP_CREATE_EWPOOL); /* stack: empty write context */
1.69      paf       334:        P($$, $1); /* some code that writes to that context */
1.54      paf       335:        O($$, OP_REDUCE_EWPOOL); /* context=pop; stack: context.value() */
1.1       paf       336: };
1.55      paf       337: constructor_code: codes__excluding_sole_str_literal;
1.27      paf       338: codes__excluding_sole_str_literal: action | code codes { $$=$1; P($$, $2) };
                    339: 
1.1       paf       340: /* call */
                    341: 
1.66      paf       342: call: call_value {
                    343:        $$=$1; /* stack: value */
1.102     paf       344:        O($$, OP_WRITE_VALUE); /* value=pop; wcontext.write(value) */
1.66      paf       345: };
                    346: call_value: '^' call_name store_params EON { /* ^field.$method{vasya} */
1.42      paf       347:        $$=$2; /* with_xxx,diving code; stack: context,method_junction */
1.54      paf       348:        O($$, OP_GET_METHOD_FRAME); /* stack: context,method_frame */
1.123     paf       349: 
                    350:        YYSTYPE params_code=$3;
                    351:        if(params_code->size()==3) // probably [] case. [OP_VALUE + Unknown + STORE_PARAM]
                    352:                if(Value *value=LA2V(params_code)) // it is OP_VALUE + value?
                    353:                        if(!value->is_defined()) // value is VUnknown?
                    354:                                params_code=0; // ^zzz[] case. don't append lone empty param.
                    355:        if(params_code)
                    356:                P($$, params_code); // filling method_frame.store_params
                    357:        O($$, OP_CALL); // method_frame=pop; ncontext=pop; call(ncontext,method_frame) stack: value
1.1       paf       358: };
                    359: 
1.43      paf       360: call_name: name_without_curly_rdive;
1.38      paf       361: 
1.9       paf       362: store_params: store_param | store_params store_param { $$=$1; P($$, $2) };
1.69      paf       363: store_param: 
                    364:        store_square_param
                    365: |      store_round_param
                    366: |      store_curly_param
1.31      paf       367: ;
1.123     paf       368: store_square_param: '[' store_code_param_parts ']' {$$=$2};
1.69      paf       369: store_round_param: '(' store_expr_param_parts ')' {$$=$2};
1.94      paf       370: store_curly_param: '{' store_curly_param_parts '}' {$$=$2};
1.69      paf       371: store_code_param_parts:
                    372:        store_code_param_part
                    373: |      store_code_param_parts ';' store_code_param_part { $$=$1; P($$, $3) }
                    374: ;
                    375: store_expr_param_parts:
                    376:        store_expr_param_part
                    377: |      store_expr_param_parts ';' store_expr_param_part { $$=$1; P($$, $3) }
                    378: ;
1.94      paf       379: store_curly_param_parts:
                    380:        store_curly_param_part
                    381: |      store_curly_param_parts ';' store_curly_param_part { $$=$1; P($$, $3) }
                    382: ;
1.120     paf       383: store_code_param_part: code_param_value {
1.32      paf       384:        $$=$1;
1.54      paf       385:        O($$, OP_STORE_PARAM);
1.120     paf       386: };
1.69      paf       387: store_expr_param_part: write_expr_value {
                    388:        $$=N(POOL); 
1.103     paf       389:        PEA($$, $1);
1.69      paf       390: };
1.94      paf       391: store_curly_param_part: maybe_codes {
                    392:        $$=N(POOL); 
                    393:        PCA($$, $1);
                    394: };
1.120     paf       395: code_param_value:
                    396:        unknown_value /* optimized [;...] case */
                    397: |      STRING /* optimized [STRING] case */
                    398: |      constructor_code_value /* [something complex] */
                    399: ;
1.90      paf       400: write_expr_value: expr_value {
1.69      paf       401:        $$=$1;
1.102     paf       402:        O($$, OP_WRITE_EXPR_RESULT);
1.69      paf       403: };
1.1       paf       404: 
                    405: /* name */
                    406: 
1.20      paf       407: name_expr_dive_code: name_expr_value | name_path name_expr_value { $$=$1; P($$, $2) };
1.1       paf       408: 
1.9       paf       409: name_path: name_step | name_path name_step { $$=$1; P($$, $2) };
1.1       paf       410: name_step: name_advance1 '.';
                    411: name_advance1: name_expr_value {
                    412:        /* stack: context */
                    413:        $$=$1; /* stack: context,name */
1.54      paf       414:        O($$, OP_GET_ELEMENT); /* name=pop; context=pop; stack: context.get_element(name) */
1.1       paf       415: };
                    416: name_advance2: name_expr_value {
                    417:        /* stack: context */
                    418:        $$=$1; /* stack: context,name */
1.54      paf       419:        O($$, OP_GET_ELEMENT); /* name=pop; context=pop; stack: context.get_element(name) */
1.1       paf       420: }
1.4       paf       421: |      STRING BOGUS
1.1       paf       422: ;
                    423: name_expr_value: 
1.4       paf       424:        STRING /* subname_is_const */
1.1       paf       425: |      name_expr_subvar_value /* $subname_is_var_value */
                    426: |      name_expr_with_subvar_value /* xxx$part_of_subname_is_var_value[$...] */
                    427: ;
                    428: name_expr_subvar_value: '$' subvar_ref_name_rdive {
                    429:        $$=$2;
1.54      paf       430:        O($$, OP_GET_ELEMENT);
1.1       paf       431: };
1.4       paf       432: name_expr_with_subvar_value: STRING subvar_get_writes {
1.25      paf       433:        $$=N(POOL); 
1.54      paf       434:        O($$, OP_CREATE_EWPOOL);
1.9       paf       435:        P($$, $1);
1.102     paf       436:        O($$, OP_WRITE_VALUE);
1.9       paf       437:        P($$, $2);
1.54      paf       438:        O($$, OP_REDUCE_EWPOOL);
1.1       paf       439: };
1.18      paf       440: subvar_ref_name_rdive: subvar_ref_name_rdive_read | subvar_ref_name_rdive_root;
                    441: subvar_ref_name_rdive_read: STRING {
1.25      paf       442:        $$=N(POOL); 
1.54      paf       443:        O($$, OP_WITH_READ);
1.9       paf       444:        P($$, $1);
1.1       paf       445: };
1.18      paf       446: subvar_ref_name_rdive_root: ':' STRING {
1.25      paf       447:        $$=N(POOL); 
1.54      paf       448:        O($$, OP_WITH_ROOT);
1.18      paf       449:        P($$, $2);
                    450: };
1.9       paf       451: subvar_get_writes: subvar__get_write | subvar_get_writes subvar__get_write { $$=$1; P($$, $2) };
1.1       paf       452: subvar__get_write: '$' subvar_ref_name_rdive {
                    453:        $$=$2;
1.54      paf       454:        O($$, OP_GET_ELEMENT__WRITE);
1.42      paf       455: };
                    456: 
1.44      paf       457: class_prefix: STRING ':' {
1.72      paf       458:        $$=$1; // stack: class name string
                    459:        O($$, OP_GET_CLASS);
1.1       paf       460: };
                    461: 
                    462: 
                    463: /* with */
                    464: 
                    465: with: '$' name_without_curly_rdive '{' codes '}' {
                    466:        $$=$2;
1.54      paf       467:        O($$, OP_CREATE_RWPOOL);
1.9       paf       468:        P($$, $4);
1.54      paf       469:        O($$, OP_REDUCE_RWPOOL);
1.102     paf       470:        O($$, OP_WRITE_VALUE);
1.1       paf       471: };
1.53      paf       472: 
1.56      paf       473: /* expr */
1.53      paf       474: 
1.81      paf       475: expr_value: expr {
                    476:        if(($$=$1)->size()==2) // only one string literal in there?
1.62      paf       477:                change_string_literal_to_double_literal($$); // make that string literal Double
                    478: };
1.56      paf       479: expr: 
1.62      paf       480:        STRING
1.64      paf       481: |      get_value
1.66      paf       482: |      call_value
1.64      paf       483: |      '"' string_inside_quotes_value '"' { $$ = $2; }
1.60      paf       484: |      '(' expr ')' { $$ = $2; }
                    485: /* stack: operand // stack: @operand */
                    486: |      '-' expr %prec NEG { $$=$2;  O($$, OP_NEG) }
1.68      paf       487: |      '~' expr { $$=$2;        O($$, OP_INV) }
                    488: |      '!' expr { $$=$2;  O($$, OP_NOT) }
                    489: |      "def" expr { $$=$2;  O($$, OP_DEF) }
                    490: |      "in" expr { $$=$2;  O($$, OP_IN) }
                    491: |      "-f" expr { $$=$2;  O($$, OP_FEXISTS) }
1.127     paf       492: |      "-d" expr { $$=$2;  O($$, OP_DEXISTS) }
1.60      paf       493: /* stack: a,b // stack: a@b */
                    494: |      expr '-' expr { $$=$1;  P($$, $3);  O($$, OP_SUB) }
                    495: |      expr '+' expr { $$=$1;  P($$, $3);  O($$, OP_ADD) }
                    496: |      expr '*' expr { $$=$1;  P($$, $3);  O($$, OP_MUL) }
                    497: |      expr '/' expr { $$=$1;  P($$, $3);  O($$, OP_DIV) }
                    498: |      expr '%' expr { $$=$1;  P($$, $3);  O($$, OP_MOD) }
                    499: |      expr '&' expr { $$=$1;  P($$, $3);  O($$, OP_BIN_AND) }
                    500: |      expr '|' expr { $$=$1;  P($$, $3);  O($$, OP_BIN_OR) }
                    501: |      expr '#' expr { $$=$1;  P($$, $3);  O($$, OP_BIN_XOR) }
                    502: |      expr "&&" expr { $$=$1;  P($$, $3);  O($$, OP_LOG_AND) }
                    503: |      expr "||" expr { $$=$1;  P($$, $3);  O($$, OP_LOG_OR) }
                    504: |      expr "##" expr { $$=$1;  P($$, $3);  O($$, OP_LOG_XOR) }
                    505: |      expr '<' expr { $$=$1;  P($$, $3);  O($$, OP_NUM_LT) }
                    506: |      expr '>' expr { $$=$1;  P($$, $3);  O($$, OP_NUM_GT) }
                    507: |      expr "<=" expr { $$=$1;  P($$, $3);  O($$, OP_NUM_LE) }
                    508: |      expr ">=" expr { $$=$1;  P($$, $3);  O($$, OP_NUM_GE) }
                    509: |      expr "==" expr { $$=$1;  P($$, $3);  O($$, OP_NUM_EQ) }
                    510: |      expr "!=" expr { $$=$1;  P($$, $3);  O($$, OP_NUM_NE) }
1.61      paf       511: |      expr "lt" expr { $$=$1;  P($$, $3);  O($$, OP_STR_LT) }
                    512: |      expr "gt" expr { $$=$1;  P($$, $3);  O($$, OP_STR_GT) }
                    513: |      expr "le" expr { $$=$1;  P($$, $3);  O($$, OP_STR_LE) }
                    514: |      expr "ge" expr { $$=$1;  P($$, $3);  O($$, OP_STR_GE) }
                    515: |      expr "eq" expr { $$=$1;  P($$, $3);  O($$, OP_STR_EQ) }
                    516: |      expr "ne" expr { $$=$1;  P($$, $3);  O($$, OP_STR_NE) }
1.95      paf       517: |      expr "is" expr { $$=$1;  P($$, $3);  O($$, OP_IS) }
1.56      paf       518: ;
1.55      paf       519: 
1.65      paf       520: string_inside_quotes_value: maybe_codes {
1.64      paf       521:        $$=N(POOL);
                    522:        O($$, OP_CREATE_SWPOOL); /* stack: empty write context */
1.69      paf       523:        P($$, $1); /* some code that writes to that context */
1.64      paf       524:        O($$, OP_REDUCE_SWPOOL); /* context=pop; stack: context.get_string() */
1.53      paf       525: };
1.1       paf       526: 
1.27      paf       527: /* basics */
1.1       paf       528: 
1.81      paf       529: write_string: STRING {
1.102     paf       530:        // optimized from OP_STRING+OP_WRITE_VALUE to OP_STRING__WRITE
1.84      paf       531:        change_string_literal_to_write_string_literal($$=$1)
1.54      paf       532: };
                    533: 
1.120     paf       534: unknown_value: /* empty */ { $$=VL(NEW VUnknown(POOL)) };
1.25      paf       535: empty: /* empty */ { $$=N(POOL) };
1.1       paf       536: 
                    537: %%
1.105     paf       538: #endif
1.1       paf       539: 
                    540: /*
                    541:        000$111(2222)00 
                    542:                000$111{3333}00
1.9       paf       543:        $,^: push,=0
1.1       paf       544:        1:( { break=pop
                    545:        2:( )  pop
                    546:        3:{ }  pop
                    547: 
                    548:        000^111(2222)4444{33333}4000
1.9       paf       549:        $,^: push,=0
1.1       paf       550:        1:( { break=pop
                    551:        2:( )=4
                    552:        3:{ }=4
                    553:                4:[^({]=pop
                    554: */
                    555: 
1.110     paf       556: static int yylex(YYSTYPE *lvalp, void *pc) {
1.114     paf       557:        #define lexical_brackets_nestage PC.brackets_nestages[PC.sp]
1.48      paf       558:        #define RC {result=c; goto break2; }
1.1       paf       559: 
                    560:     register int c;
                    561:     int result;
                    562:        
1.114     paf       563:        if(PC.pending_state) {
                    564:                result=PC.pending_state;
                    565:                PC.pending_state=0;
1.1       paf       566:                return result;
                    567:        }
                    568:        
1.114     paf       569:        const char *begin=PC.source;
1.91      paf       570:        const char *end;
1.114     paf       571:        int begin_line=PC.line;
1.67      paf       572:        int skip_analized=0;
1.50      paf       573:        while(true) {
1.114     paf       574:                c=*(end=(PC.source++));
1.1       paf       575: 
1.4       paf       576:                if(c=='\n') {
1.114     paf       577:                        PC.line++;
                    578:                        PC.col=0;
1.10      paf       579:                } else
1.114     paf       580:                        PC.col++;
1.73      paf       581: 
1.119     paf       582:                if(c=='^' && PC.ls!=LS_COMMENT && PC.ls!=LS_DEF_COMMENT) 
1.114     paf       583:                        switch(*PC.source) {
1.126     paf       584:                        // escaping: ^^ & co
1.48      paf       585:                        case '^': case '$': case ';':
1.126     paf       586:                        case '(': case ')':
1.48      paf       587:                        case '[': case ']':
                    588:                        case '{': case '}':
1.114     paf       589:                        case '"': 
1.40      paf       590:                                if(end!=begin) {
                    591:                                        // append piece till ^
1.121     paf       592:                                        PC.string->APPEND_CLEAN(begin, end-begin, PC.file, begin_line);
1.40      paf       593:                                }
1.63      paf       594:                                // reset piece 'begin' position & line
1.114     paf       595:                                begin=PC.source; // ^
                    596:                                begin_line=PC.line;
1.40      paf       597:                                // skip over ^ and _
1.114     paf       598:                                PC.source++;  PC.col++;
1.40      paf       599:                                // skip analysis = forced literal
1.1       paf       600:                                continue;
1.114     paf       601: 
                    602:                        // converting ^#HH into char(hex(HH))
                    603:                        case '#':
                    604:                                if(end!=begin) {
                    605:                                        // append piece till ^
1.121     paf       606:                                        PC.string->APPEND_CLEAN(begin, end-begin, PC.file, begin_line);
1.114     paf       607:                                }
                    608:                                // #HH ?
                    609:                                if(PC.source[0]=='#' && PC.source[1] && PC.source[2]) {
                    610:                                        char *hex=(char *)POOL.malloc(1);
                    611:                                        hex[0]=
                    612:                                                hex_value[(unsigned char)PC.source[1]]*0x10+
                    613:                                                hex_value[(unsigned char)PC.source[2]];
                    614:                                        if(hex[0]==0) {
                    615:                                                result=BAD_HEX_LITERAL;
                    616:                                                goto break2; // wrong hex value[no ^#00 chars allowed]: bail out
                    617:                                        }
                    618:                                        // append char(hex(HH))
1.121     paf       619:                                        PC.string->APPEND_CLEAN(hex, 1, PC.file, begin_line);
1.114     paf       620:                                        // skip over ^#HH
                    621:                                        PC.source+=3;
                    622:                                        PC.col+=3;
                    623:                                        // reset piece 'begin' position & line
                    624:                                        begin=PC.source; // ^
                    625:                                        begin_line=PC.line;
                    626:                                        continue;
                    627:                                }
                    628:                                break;
1.1       paf       629:                        }
1.113     paf       630:                // #comment  start skipping
1.114     paf       631:                if(c=='#' && PC.col==1) {
1.112     paf       632:                        if(end!=begin) {
                    633:                                // append piece till #
1.121     paf       634:                                PC.string->APPEND_CLEAN(begin, end-begin, PC.file, begin_line);
1.112     paf       635:                        }
                    636:                        // fall into COMMENT lexical state [wait for \n]
                    637:                        push_LS(PC, LS_COMMENT);
                    638:                }
1.114     paf       639:                switch(PC.ls) {
1.10      paf       640: 
                    641:                // USER'S = NOT OURS
1.1       paf       642:                case LS_USER:
1.48      paf       643:                        switch(c) {
                    644:                        case '$':
1.10      paf       645:                                push_LS(PC, LS_VAR_NAME_SIMPLE);
1.48      paf       646:                                RC;
                    647:                        case '^':
                    648:                                push_LS(PC, LS_METHOD_NAME);
                    649:                                RC;
                    650:                        case '@':
1.114     paf       651:                                if(PC.col==0+1) {
1.48      paf       652:                                        push_LS(PC, LS_DEF_NAME);
                    653:                                        RC;
                    654:                                }
                    655:                                break;
1.112     paf       656:                        }
                    657:                        break;
                    658:                        
                    659:                // #COMMENT
                    660:                case LS_COMMENT:
                    661:                        if(c=='\n') {
                    662:                                // skip comment
1.114     paf       663:                                begin=PC.source;
                    664:                                begin_line=PC.line;
1.112     paf       665: 
                    666:                                pop_LS(PC);
                    667:                                continue;
1.1       paf       668:                        }
1.48      paf       669:                        break;
                    670:                        
                    671:                // STRING IN EXPRESSION
                    672:                case LS_EXPRESSION_STRING:
                    673:                        switch(c) {
                    674:                        case '"':
                    675:                                pop_LS(PC); //"abc".
                    676:                                RC;
                    677:                        case '$':
                    678:                                push_LS(PC, LS_VAR_NAME_SIMPLE);
                    679:                                RC;
                    680:                        case '^':
1.10      paf       681:                                push_LS(PC, LS_METHOD_NAME);
1.48      paf       682:                                RC;
1.10      paf       683:                        }
                    684:                        break;
                    685: 
                    686:                // METHOD DEFINITION
                    687:                case LS_DEF_NAME:
1.48      paf       688:                        switch(c) {
                    689:                        case '[':
1.114     paf       690:                                PC.ls=LS_DEF_PARAMS;
1.48      paf       691:                                RC;
                    692:                        case '\n':
1.114     paf       693:                                PC.ls=LS_DEF_SPECIAL_BODY;
1.48      paf       694:                                RC;
1.10      paf       695:                        }
                    696:                        break;
1.48      paf       697: 
1.10      paf       698:                case LS_DEF_PARAMS:
1.48      paf       699:                        switch(c) {
                    700:                        case ';':
                    701:                                RC;
                    702:                        case ']':
1.114     paf       703:                                PC.ls=*PC.source=='['?LS_DEF_LOCALS:LS_DEF_COMMENT;
1.48      paf       704:                                RC;
1.49      paf       705:                        case '\n': // wrong. bailing out
1.10      paf       706:                                pop_LS(PC);
1.48      paf       707:                                RC;
1.10      paf       708:                        }
                    709:                        break;
1.48      paf       710: 
1.10      paf       711:                case LS_DEF_LOCALS:
1.48      paf       712:                        switch(c) {
                    713:                        case '[':
                    714:                        case ';':
                    715:                                RC;
                    716:                        case ']':
1.114     paf       717:                                PC.ls=LS_DEF_COMMENT;
1.48      paf       718:                                RC;
                    719:                        case '\n': // wrong. bailing out
1.10      paf       720:                                pop_LS(PC);
1.48      paf       721:                                RC;
1.10      paf       722:                        }
                    723:                        break;
1.48      paf       724: 
1.10      paf       725:                case LS_DEF_COMMENT:
                    726:                        if(c=='\n') {
                    727:                                pop_LS(PC);
1.48      paf       728:                                RC;
1.37      paf       729:                        }
                    730:                        break;
                    731: 
1.48      paf       732:                case LS_DEF_SPECIAL_BODY:
1.37      paf       733:                        if(c=='\n') {
1.114     paf       734:                                switch(*PC.source) {
1.48      paf       735:                                case '@': case 0: // end of special_code
1.37      paf       736:                                        pop_LS(PC);
1.48      paf       737:                                        break;
                    738:                                }
                    739:                                RC;
                    740:                        }
                    741:                        break;
                    742: 
                    743:                // (EXPRESSION)
1.69      paf       744:                case LS_VAR_ROUND:
                    745:                case LS_METHOD_ROUND:
1.48      paf       746:                        switch(c) {
                    747:                        case ')':
                    748:                                if(--lexical_brackets_nestage==0)
1.114     paf       749:                                        if(PC.ls==LS_METHOD_ROUND) // method round param ended
                    750:                                                PC.ls=LS_METHOD_AFTER; // look for method end
                    751:                                        else // PC.ls==LS_VAR_ROUND // variable constructor ended
1.69      paf       752:                                                pop_LS(PC); // return to normal life
1.48      paf       753:                                RC;
                    754:                        case '$':
1.69      paf       755:                                push_LS(PC, LS_EXPRESSION_VAR_NAME);                            
1.48      paf       756:                                RC;
                    757:                        case '^':
                    758:                                push_LS(PC, LS_METHOD_NAME);
                    759:                                RC;
                    760:                        case '(':
                    761:                                lexical_brackets_nestage++;
                    762:                                RC;
1.67      paf       763:                        case '-':
1.127     paf       764:                                switch(*PC.source) {
                    765:                                case 'f': // -f
1.67      paf       766:                                        skip_analized=1;
                    767:                                        result=FEXISTS;
1.127     paf       768:                                        goto break2;
                    769:                                case 'd': // -d
                    770:                                        skip_analized=1;
                    771:                                        result=DEXISTS;
                    772:                                        goto break2;
                    773:                                default:
1.67      paf       774:                                        result=c;
1.127     paf       775:                                        goto break2;
                    776:                                }
1.67      paf       777:                                goto break2;
                    778:                        case '+': case '*': case '/': case '%': 
1.58      paf       779:                        case '~':
1.48      paf       780:                        case ';':
                    781:                                RC;
1.59      paf       782:                        case '&': case '|':  case '#':
1.114     paf       783:                                if(*PC.source==c) { // && ||
1.59      paf       784:                                        result=c=='#'?LXOR:c=='&'?LAND:LOR;
1.67      paf       785:                                        skip_analized=1;
1.58      paf       786:                                } else
                    787:                                        result=c;
                    788:                                goto break2;
                    789:                        case '<': case '>': case '=': case '!': 
1.114     paf       790:                                if(*PC.source=='=') { // <= >= == !=
1.67      paf       791:                                        skip_analized=1;
1.58      paf       792:                                        switch(c) {
                    793:                                        case '<': result=NLE; break;
                    794:                                        case '>': result=NGE; break;
                    795:                                        case '=': result=NEQ; break;
                    796:                                        case '!': result=NNE; break;
                    797:                                        }
                    798:                                } else
                    799:                                        result=c;
                    800:                                goto break2;
1.48      paf       801:                        case '"':
                    802:                                push_LS(PC, LS_EXPRESSION_STRING);
                    803:                                RC;
1.50      paf       804:                        case 'l': case 'g': case 'e': case 'n':
1.51      paf       805:                                if(end==begin) // right after whitespace
1.117     paf       806:                                        if(isspace(PC.source[1])) {
                    807:                                                switch(*PC.source) {
                    808:                                                        //                                      case '?': // ok [and bad cases, yacc would bark at them]
                    809:                                                case 't': // lt gt [et nt]
                    810:                                                        result=c=='l'?SLT:c=='g'?SGT:BAD_STRING_COMPARISON_OPERATOR;
                    811:                                                        skip_analized=1;
                    812:                                                        goto break2;
                    813:                                                case 'e': // le ge ne [ee]
                    814:                                                        result=c=='l'?SLE:c=='g'?SGE:c=='n'?SNE:BAD_STRING_COMPARISON_OPERATOR;
                    815:                                                        skip_analized=1;
                    816:                                                        goto break2;
                    817:                                                case 'q': // eq [lq gq nq]
                    818:                                                        result=c=='e'?SEQ:BAD_STRING_COMPARISON_OPERATOR;
                    819:                                                        skip_analized=1;
                    820:                                                        goto break2;
                    821:                                                }
1.67      paf       822:                                        }
                    823:                                break;
                    824:                        case 'i':
                    825:                                if(end==begin) // right after whitespace
1.117     paf       826:                                        if(isspace(PC.source[1])) {
                    827:                                                switch(PC.source[0]) {
                    828:                                                case 'n': // in
1.95      paf       829:                                                        skip_analized=1;
                    830:                                                        result=IN;
                    831:                                                        goto break2;
1.117     paf       832:                                                case 's': // is
1.95      paf       833:                                                        skip_analized=1;
                    834:                                                        result=IS;
                    835:                                                        goto break2;
                    836:                                                }
1.67      paf       837:                                        }
                    838:                                break;
                    839:                        case 'd':
                    840:                                if(end==begin) // right after whitespace
1.114     paf       841:                                        if(PC.source[0]=='e' && PC.source[1]=='f') { // def
1.67      paf       842:                                                skip_analized=2;
                    843:                                                result=DEF;
1.58      paf       844:                                                goto break2;
1.50      paf       845:                                        }
1.48      paf       846:                                break;
                    847:                        case ' ': case '\t': case '\n':
1.63      paf       848:                                if(end!=begin) { // there were a string after previous operator?
                    849:                                        result=0; // return that string
                    850:                                        goto break2;
1.48      paf       851:                                }
1.63      paf       852:                                // that's a leading|traling space or after-operator-space
                    853:                                // ignoring it
                    854:                                // reset piece 'begin' position & line
1.114     paf       855:                                begin=PC.source; // after whitespace char
                    856:                                begin_line=PC.line;
1.48      paf       857:                                continue;
1.1       paf       858:                        }
                    859:                        break;
                    860: 
1.10      paf       861:                // VARIABLE GET/PUT/WITH
1.1       paf       862:                case LS_VAR_NAME_SIMPLE:
1.69      paf       863:                case LS_EXPRESSION_VAR_NAME:
1.114     paf       864:                        if(PC.ls==LS_EXPRESSION_VAR_NAME) {
1.56      paf       865:                                // name in expr ends also before binary operators 
1.48      paf       866:                                switch(c) {
1.92      paf       867:                                case '-': 
1.48      paf       868:                                        pop_LS(PC);
1.114     paf       869:                                        PC.source--;  if(--PC.col<0) { PC.line--;  PC.col=-1; }
1.48      paf       870:                                        result=EON;
                    871:                                        goto break2;
                    872:                                }
                    873:                        }
                    874:                        switch(c) {
                    875:                        case 0:
                    876:                        case ' ': case '\t': case '\n':
                    877:                        case ';':
1.126     paf       878:                        case ']': case '}': case ')': 
                    879:                        case '"': case '\'':
1.83      paf       880:                        case '<': case '>':  // these stand for HTML brackets and expression binary ops
1.92      paf       881:                        case '+': case '*': case '/': case '%': 
                    882:                        case '&': case '|': 
                    883:                        case '=': case '!':
1.99      paf       884:                        // common delimiters
1.126     paf       885:                        case ',':
1.1       paf       886:                                pop_LS(PC);
1.114     paf       887:                                PC.source--;  if(--PC.col<0) { PC.line--;  PC.col=-1; }
1.13      paf       888:                                result=EON;
1.1       paf       889:                                goto break2;
1.48      paf       890:                        case '[':
1.114     paf       891:                                PC.ls=LS_VAR_SQUARE;
1.1       paf       892:                                lexical_brackets_nestage=1;
1.48      paf       893:                                RC;
                    894:                        case '{':
                    895:                                if(begin==end) { // ${name}, no need of EON, switching LS
1.114     paf       896:                                        PC.ls=LS_VAR_NAME_CURLY; 
1.48      paf       897:                                } else {
1.114     paf       898:                                        PC.ls=LS_VAR_CURLY;
1.48      paf       899:                                        lexical_brackets_nestage=1;
                    900:                                }
1.69      paf       901: 
1.48      paf       902:                                RC;
                    903:                        case '(':
1.114     paf       904:                                PC.ls=LS_VAR_ROUND;
1.1       paf       905:                                lexical_brackets_nestage=1;
1.48      paf       906:                                RC;
                    907:                        case '.': // name part delim
                    908:                        case '$': // name part subvar
                    909:                        case ':': // ':name' or 'class:name'
                    910:                                RC;
1.1       paf       911:                        }
                    912:                        break;
1.48      paf       913: 
1.1       paf       914:                case LS_VAR_NAME_CURLY:
1.48      paf       915:                        switch(c) {
                    916:                        case '}': // ${name} finished, restoring LS
1.1       paf       917:                                pop_LS(PC);
1.48      paf       918:                                RC;
                    919:                        case '.': // name part delim
                    920:                        case '$': // name part subvar
                    921:                        case ':': // ':name' or 'class:name'
                    922:                                RC;
1.1       paf       923:                        }
                    924:                        break;
1.48      paf       925: 
                    926:                case LS_VAR_SQUARE:
                    927:                        switch(c) {
                    928:                        case '$':
1.10      paf       929:                                push_LS(PC, LS_VAR_NAME_SIMPLE);
1.48      paf       930:                                RC;
                    931:                        case '^':
1.10      paf       932:                                push_LS(PC, LS_METHOD_NAME);
1.48      paf       933:                                RC;
                    934:                        case ']':
1.1       paf       935:                                if(--lexical_brackets_nestage==0) {
                    936:                                        pop_LS(PC);
1.48      paf       937:                                        RC;
1.1       paf       938:                                }
1.48      paf       939:                                break;
                    940:                        case ';': // operator_or_fmt;value delim
                    941:                                RC;
                    942:                        case '[':
                    943:                                lexical_brackets_nestage++;
                    944:                                break;
1.1       paf       945:                        }
                    946:                        break;
1.48      paf       947: 
1.1       paf       948:                case LS_VAR_CURLY:
1.48      paf       949:                        switch(c) {
                    950:                        case '$':
1.10      paf       951:                                push_LS(PC, LS_VAR_NAME_SIMPLE);
1.48      paf       952:                                RC;
                    953:                        case '^':
1.10      paf       954:                                push_LS(PC, LS_METHOD_NAME);
1.48      paf       955:                                RC;
                    956:                        case '}':
1.1       paf       957:                                if(--lexical_brackets_nestage==0) {
                    958:                                        pop_LS(PC);
1.48      paf       959:                                        RC;
1.1       paf       960:                                }
1.48      paf       961:                                break;
                    962:                        case '{':
1.1       paf       963:                                lexical_brackets_nestage++;
1.48      paf       964:                                break;
                    965:                        }
1.1       paf       966:                        break;
                    967: 
1.10      paf       968:                // METHOD CALL
1.1       paf       969:                case LS_METHOD_NAME:
1.48      paf       970:                        switch(c) {
                    971:                        case '[':
1.114     paf       972:                                PC.ls=LS_METHOD_SQUARE;
1.1       paf       973:                                lexical_brackets_nestage=1;
1.48      paf       974:                                RC;
                    975:                        case '{':
1.114     paf       976:                                PC.ls=LS_METHOD_CURLY;
1.1       paf       977:                                lexical_brackets_nestage=1;
1.48      paf       978:                                RC;
1.69      paf       979:                        case '(':
1.114     paf       980:                                PC.ls=LS_METHOD_ROUND;
1.69      paf       981:                                lexical_brackets_nestage=1;
                    982:                                RC;
1.48      paf       983:                        case '.': // name part delim 
                    984:                        case '$': // name part subvar
                    985:                        case ':': // ':name' or 'class:name'
                    986:                                RC;
1.1       paf       987:                        }
                    988:                        break;
1.48      paf       989: 
                    990:                case LS_METHOD_SQUARE:
                    991:                        switch(c) {
                    992:                        case '$':
1.10      paf       993:                                push_LS(PC, LS_VAR_NAME_SIMPLE);
1.48      paf       994:                                RC;
                    995:                        case '^':
1.10      paf       996:                                push_LS(PC, LS_METHOD_NAME);
1.48      paf       997:                                RC;
                    998:                        case ';': // param delim
                    999:                                RC;
                   1000:                        case ']':
1.1       paf      1001:                                if(--lexical_brackets_nestage==0) {
1.114     paf      1002:                                        PC.ls=LS_METHOD_AFTER;
1.48      paf      1003:                                        RC;
1.1       paf      1004:                                }
1.48      paf      1005:                                break;
                   1006:                        case '[':
1.1       paf      1007:                                lexical_brackets_nestage++;
1.48      paf      1008:                                break;
                   1009:                        }
1.1       paf      1010:                        break;
1.48      paf      1011: 
1.1       paf      1012:                case LS_METHOD_CURLY:
1.48      paf      1013:                        switch(c) {
                   1014:                        case '$':
1.10      paf      1015:                                push_LS(PC, LS_VAR_NAME_SIMPLE);
1.48      paf      1016:                                RC;
                   1017:                        case '^':
1.10      paf      1018:                                push_LS(PC, LS_METHOD_NAME);
1.94      paf      1019:                                RC;
                   1020:                        case ';': // param delim
1.48      paf      1021:                                RC;
                   1022:                        case '}':
1.1       paf      1023:                                if(--lexical_brackets_nestage==0) {
1.114     paf      1024:                                        PC.ls=LS_METHOD_AFTER;
1.48      paf      1025:                                        RC;
1.1       paf      1026:                                }
1.48      paf      1027:                                break;
                   1028:                        case '{':
1.1       paf      1029:                                lexical_brackets_nestage++;
1.48      paf      1030:                                break;
                   1031:                        }
1.1       paf      1032:                        break;
1.48      paf      1033: 
1.1       paf      1034:                case LS_METHOD_AFTER:
1.69      paf      1035:                        if(c=='[') {/* ][ }[ )[ */
1.114     paf      1036:                                PC.ls=LS_METHOD_SQUARE;
1.1       paf      1037:                                lexical_brackets_nestage=1;
1.48      paf      1038:                                RC;
1.1       paf      1039:                        }                                          
1.69      paf      1040:                        if(c=='{') {/* ]{ }{ ){ */
1.114     paf      1041:                                PC.ls=LS_METHOD_CURLY;
1.69      paf      1042:                                lexical_brackets_nestage=1;
                   1043:                                RC;
                   1044:                        }                                          
                   1045:                        if(c=='(') {/* ]( }( )( */
1.114     paf      1046:                                PC.ls=LS_METHOD_ROUND;
1.1       paf      1047:                                lexical_brackets_nestage=1;
1.48      paf      1048:                                RC;
1.1       paf      1049:                        }                                          
                   1050:                        pop_LS(PC);
1.114     paf      1051:                        PC.source--;  if(--PC.col<0) { PC.line--;  PC.col=-1; }
1.13      paf      1052:                        result=EON;
1.1       paf      1053:                        goto break2;
                   1054:                }
1.9       paf      1055:                if(c==0) {
1.1       paf      1056:                        result=-1;
                   1057:                        break;
                   1058:                }
                   1059:        }
                   1060: 
                   1061: break2:
1.59      paf      1062:        if(end!=begin) { // there is last piece?
                   1063:                if((c=='@' || c==0) && end[-1]=='\n') { // we are before LS_DEF_NAME or EOF?
                   1064:                        // strip last \n
1.10      paf      1065:                        end--;
1.59      paf      1066:                }
                   1067:                if(end!=begin) { // last piece still alive?
                   1068:                        // append it
1.121     paf      1069:                        PC.string->APPEND_CLEAN(begin, end-begin, PC.file, begin_line/*, start_col*/);
1.30      paf      1070:                }
1.59      paf      1071:        }
1.114     paf      1072:        if(PC.string->size()) { // something accumulated?
1.17      paf      1073:                // create STRING value: array of OP_VALUE+vstring
1.114     paf      1074:                *lvalp=VL(NEW VString(*PC.string));
1.10      paf      1075:                // new pieces storage
1.114     paf      1076:                PC.string=NEW String(POOL);
1.58      paf      1077:                // make current result be pending for next call, return STRING for now
1.114     paf      1078:                PC.pending_state=result;  result=STRING;
1.58      paf      1079:        }
1.67      paf      1080:        if(skip_analized) {
1.114     paf      1081:                PC.source+=skip_analized;  PC.col+=skip_analized;
1.1       paf      1082:        }
1.58      paf      1083:        return result;
1.1       paf      1084: }
                   1085: 
1.110     paf      1086: static int real_yyerror(parse_control *pc, char *s) {  // Called by yyparse on error
1.114     paf      1087:           strncpy(PC.error, s, MAX_STRING);
1.1       paf      1088:           return 1;
1.110     paf      1089: }
1.1       paf      1090: 
1.110     paf      1091: static void yyprint(FILE *file, int type, YYSTYPE value) {
                   1092:        if(type==STRING)
1.120     paf      1093:                fprintf(file, " \"%s\"", LA2S(value)->cstr());
1.110     paf      1094: }

E-mail: