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

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

E-mail: