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

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.88      paf         7: */
1.144     parser      8: %{
1.166     parser      9: static char *RCSId="$Id: compile.y,v 1.165.4.2 2001/09/17 14:26:56 parser Exp $"; 
1.88      paf        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.119     paf       587:                if(c=='^' && PC.ls!=LS_COMMENT && PC.ls!=LS_DEF_COMMENT) 
1.114     paf       588:                        switch(*PC.source) {
1.165     parser    589:                        // ^escaping some punctuators
1.48      paf       590:                        case '^': case '$': case ';':
1.126     paf       591:                        case '(': case ')':
1.48      paf       592:                        case '[': case ']':
                    593:                        case '{': case '}':
1.114     paf       594:                        case '"': 
1.40      paf       595:                                if(end!=begin) {
                    596:                                        // append piece till ^
1.121     paf       597:                                        PC.string->APPEND_CLEAN(begin, end-begin, PC.file, begin_line);
1.40      paf       598:                                }
1.63      paf       599:                                // reset piece 'begin' position & line
1.164     parser    600:                                end=begin=PC.source; // ^
1.114     paf       601:                                begin_line=PC.line;
1.164     parser    602:                                if(PC.ls==LS_METHOD_AFTER) {
                    603:                                        pop_LS(PC);
                    604:                                        result=EON;
1.165     parser    605:                                        skip_analized=-1; // return to ^ afterwards to assure it's literality
1.164     parser    606:                                        goto break2;
                    607:                                } else {
                    608:                                        // skip over _ after ^
                    609:                                        PC.source++;  PC.col++;
                    610:                                        // skip analysis = forced literal
                    611:                                        continue;
                    612:                                }
1.114     paf       613: 
                    614:                        // converting ^#HH into char(hex(HH))
                    615:                        case '#':
                    616:                                if(end!=begin) {
                    617:                                        // append piece till ^
1.121     paf       618:                                        PC.string->APPEND_CLEAN(begin, end-begin, PC.file, begin_line);
1.114     paf       619:                                }
                    620:                                // #HH ?
                    621:                                if(PC.source[0]=='#' && PC.source[1] && PC.source[2]) {
                    622:                                        char *hex=(char *)POOL.malloc(1);
                    623:                                        hex[0]=
                    624:                                                hex_value[(unsigned char)PC.source[1]]*0x10+
                    625:                                                hex_value[(unsigned char)PC.source[2]];
                    626:                                        if(hex[0]==0) {
                    627:                                                result=BAD_HEX_LITERAL;
                    628:                                                goto break2; // wrong hex value[no ^#00 chars allowed]: bail out
                    629:                                        }
                    630:                                        // append char(hex(HH))
1.121     paf       631:                                        PC.string->APPEND_CLEAN(hex, 1, PC.file, begin_line);
1.114     paf       632:                                        // skip over ^#HH
                    633:                                        PC.source+=3;
                    634:                                        PC.col+=3;
                    635:                                        // reset piece 'begin' position & line
                    636:                                        begin=PC.source; // ^
                    637:                                        begin_line=PC.line;
                    638:                                        continue;
                    639:                                }
                    640:                                break;
1.1       paf       641:                        }
1.113     paf       642:                // #comment  start skipping
1.114     paf       643:                if(c=='#' && PC.col==1) {
1.112     paf       644:                        if(end!=begin) {
                    645:                                // append piece till #
1.121     paf       646:                                PC.string->APPEND_CLEAN(begin, end-begin, PC.file, begin_line);
1.112     paf       647:                        }
                    648:                        // fall into COMMENT lexical state [wait for \n]
                    649:                        push_LS(PC, LS_COMMENT);
                    650:                }
1.114     paf       651:                switch(PC.ls) {
1.10      paf       652: 
                    653:                // USER'S = NOT OURS
1.1       paf       654:                case LS_USER:
1.166     parser    655:         case LS_NAME_SQUARE_PART: // name.[here].xxx
1.153     parser    656:                        if(PC.trim_bof)
                    657:                                switch(c) {
                    658:                                case '\n': case ' ': case '\t':
1.152     parser    659:                                        begin=PC.source;
                    660:                                        begin_line=PC.line;
                    661:                                        continue; // skip it
1.153     parser    662:                                default:
                    663:                                        PC.trim_bof=false;
1.152     parser    664:                                }
1.48      paf       665:                        switch(c) {
                    666:                        case '$':
1.166     parser    667:                                push_LS(PC, LS_VAR_NAME_SIMPLE_WITH_COLON);
1.48      paf       668:                                RC;
                    669:                        case '^':
                    670:                                push_LS(PC, LS_METHOD_NAME);
                    671:                                RC;
                    672:                        case '@':
1.114     paf       673:                                if(PC.col==0+1) {
1.48      paf       674:                                        push_LS(PC, LS_DEF_NAME);
                    675:                                        RC;
                    676:                                }
                    677:                                break;
1.166     parser    678:                        case ']':
                    679:                                if(PC.ls==LS_NAME_SQUARE_PART)
                    680:                                        if(--lexical_brackets_nestage==0) {// $name.[co<]?>de<]?>
                    681:                                                pop_LS(PC); // $name.[co<]>de<]!>
                    682:                                                RC;
                    683:                                        }
1.160     parser    684:                                break;
1.166     parser    685:                        case '[': // $name.[co<[>de]
                    686:                                if(PC.ls==LS_NAME_SQUARE_PART)
                    687:                                        lexical_brackets_nestage++;
1.161     parser    688:                                break;
1.112     paf       689:                        }
                    690:                        break;
                    691:                        
                    692:                // #COMMENT
                    693:                case LS_COMMENT:
                    694:                        if(c=='\n') {
                    695:                                // skip comment
1.114     paf       696:                                begin=PC.source;
                    697:                                begin_line=PC.line;
1.112     paf       698: 
                    699:                                pop_LS(PC);
                    700:                                continue;
1.1       paf       701:                        }
1.48      paf       702:                        break;
                    703:                        
                    704:                // STRING IN EXPRESSION
1.145     parser    705:                case LS_EXPRESSION_STRING_QUOTED:
                    706:                case LS_EXPRESSION_STRING_APOSTROFED:
1.48      paf       707:                        switch(c) {
                    708:                        case '"':
1.145     parser    709:                        case '\'':
                    710:                                if(
                    711:                                        PC.ls == LS_EXPRESSION_STRING_QUOTED && c=='"' ||
                    712:                                        PC.ls == LS_EXPRESSION_STRING_APOSTROFED && c=='\'') {
                    713:                                        pop_LS(PC); //"abc". | 'abc'.
                    714:                                        RC;
                    715:                                }
                    716:                                break;
1.48      paf       717:                        case '$':
1.166     parser    718:                                push_LS(PC, LS_VAR_NAME_SIMPLE_WITH_COLON);
1.48      paf       719:                                RC;
                    720:                        case '^':
1.10      paf       721:                                push_LS(PC, LS_METHOD_NAME);
1.48      paf       722:                                RC;
1.10      paf       723:                        }
                    724:                        break;
                    725: 
                    726:                // METHOD DEFINITION
                    727:                case LS_DEF_NAME:
1.48      paf       728:                        switch(c) {
                    729:                        case '[':
1.114     paf       730:                                PC.ls=LS_DEF_PARAMS;
1.48      paf       731:                                RC;
                    732:                        case '\n':
1.114     paf       733:                                PC.ls=LS_DEF_SPECIAL_BODY;
1.48      paf       734:                                RC;
1.10      paf       735:                        }
                    736:                        break;
1.48      paf       737: 
1.10      paf       738:                case LS_DEF_PARAMS:
1.48      paf       739:                        switch(c) {
                    740:                        case ';':
                    741:                                RC;
                    742:                        case ']':
1.114     paf       743:                                PC.ls=*PC.source=='['?LS_DEF_LOCALS:LS_DEF_COMMENT;
1.48      paf       744:                                RC;
1.49      paf       745:                        case '\n': // wrong. bailing out
1.10      paf       746:                                pop_LS(PC);
1.48      paf       747:                                RC;
1.10      paf       748:                        }
                    749:                        break;
1.48      paf       750: 
1.10      paf       751:                case LS_DEF_LOCALS:
1.48      paf       752:                        switch(c) {
                    753:                        case '[':
                    754:                        case ';':
                    755:                                RC;
                    756:                        case ']':
1.114     paf       757:                                PC.ls=LS_DEF_COMMENT;
1.48      paf       758:                                RC;
                    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_COMMENT:
                    766:                        if(c=='\n') {
                    767:                                pop_LS(PC);
1.48      paf       768:                                RC;
1.37      paf       769:                        }
                    770:                        break;
                    771: 
1.48      paf       772:                case LS_DEF_SPECIAL_BODY:
1.147     parser    773:                        //                          @todo in case
                    774:                        // ################
                    775:                        // @next-method
                    776:                        // we are here with c=='@'
                    777:                        // which is wrong, and need action
1.37      paf       778:                        if(c=='\n') {
1.114     paf       779:                                switch(*PC.source) {
1.48      paf       780:                                case '@': case 0: // end of special_code
1.37      paf       781:                                        pop_LS(PC);
1.48      paf       782:                                        break;
                    783:                                }
                    784:                                RC;
                    785:                        }
                    786:                        break;
                    787: 
                    788:                // (EXPRESSION)
1.69      paf       789:                case LS_VAR_ROUND:
                    790:                case LS_METHOD_ROUND:
1.48      paf       791:                        switch(c) {
                    792:                        case ')':
                    793:                                if(--lexical_brackets_nestage==0)
1.114     paf       794:                                        if(PC.ls==LS_METHOD_ROUND) // method round param ended
                    795:                                                PC.ls=LS_METHOD_AFTER; // look for method end
                    796:                                        else // PC.ls==LS_VAR_ROUND // variable constructor ended
1.69      paf       797:                                                pop_LS(PC); // return to normal life
1.48      paf       798:                                RC;
                    799:                        case '$':
1.166     parser    800:                                push_LS(PC, LS_EXPRESSION_VAR_NAME_WITH_COLON);                         
1.48      paf       801:                                RC;
                    802:                        case '^':
                    803:                                push_LS(PC, LS_METHOD_NAME);
                    804:                                RC;
                    805:                        case '(':
                    806:                                lexical_brackets_nestage++;
                    807:                                RC;
1.67      paf       808:                        case '-':
1.127     paf       809:                                switch(*PC.source) {
                    810:                                case 'f': // -f
1.67      paf       811:                                        skip_analized=1;
                    812:                                        result=FEXISTS;
1.127     paf       813:                                        goto break2;
                    814:                                case 'd': // -d
                    815:                                        skip_analized=1;
                    816:                                        result=DEXISTS;
                    817:                                        goto break2;
                    818:                                default:
1.67      paf       819:                                        result=c;
1.127     paf       820:                                        goto break2;
                    821:                                }
1.67      paf       822:                                goto break2;
                    823:                        case '+': case '*': case '/': case '%': 
1.58      paf       824:                        case '~':
1.48      paf       825:                        case ';':
                    826:                                RC;
1.59      paf       827:                        case '&': case '|':  case '#':
1.114     paf       828:                                if(*PC.source==c) { // && ||
1.59      paf       829:                                        result=c=='#'?LXOR:c=='&'?LAND:LOR;
1.67      paf       830:                                        skip_analized=1;
1.58      paf       831:                                } else
                    832:                                        result=c;
                    833:                                goto break2;
                    834:                        case '<': case '>': case '=': case '!': 
1.114     paf       835:                                if(*PC.source=='=') { // <= >= == !=
1.67      paf       836:                                        skip_analized=1;
1.58      paf       837:                                        switch(c) {
                    838:                                        case '<': result=NLE; break;
                    839:                                        case '>': result=NGE; break;
                    840:                                        case '=': result=NEQ; break;
                    841:                                        case '!': result=NNE; break;
                    842:                                        }
                    843:                                } else
                    844:                                        result=c;
                    845:                                goto break2;
1.48      paf       846:                        case '"':
1.145     parser    847:                                push_LS(PC, LS_EXPRESSION_STRING_QUOTED);
                    848:                                RC;
                    849:                        case '\'':
                    850:                                push_LS(PC, LS_EXPRESSION_STRING_APOSTROFED);
1.48      paf       851:                                RC;
1.50      paf       852:                        case 'l': case 'g': case 'e': case 'n':
1.51      paf       853:                                if(end==begin) // right after whitespace
1.117     paf       854:                                        if(isspace(PC.source[1])) {
                    855:                                                switch(*PC.source) {
                    856:                                                        //                                      case '?': // ok [and bad cases, yacc would bark at them]
                    857:                                                case 't': // lt gt [et nt]
                    858:                                                        result=c=='l'?SLT:c=='g'?SGT:BAD_STRING_COMPARISON_OPERATOR;
                    859:                                                        skip_analized=1;
                    860:                                                        goto break2;
                    861:                                                case 'e': // le ge ne [ee]
                    862:                                                        result=c=='l'?SLE:c=='g'?SGE:c=='n'?SNE:BAD_STRING_COMPARISON_OPERATOR;
                    863:                                                        skip_analized=1;
                    864:                                                        goto break2;
                    865:                                                case 'q': // eq [lq gq nq]
                    866:                                                        result=c=='e'?SEQ:BAD_STRING_COMPARISON_OPERATOR;
                    867:                                                        skip_analized=1;
                    868:                                                        goto break2;
                    869:                                                }
1.67      paf       870:                                        }
                    871:                                break;
                    872:                        case 'i':
                    873:                                if(end==begin) // right after whitespace
1.117     paf       874:                                        if(isspace(PC.source[1])) {
                    875:                                                switch(PC.source[0]) {
                    876:                                                case 'n': // in
1.95      paf       877:                                                        skip_analized=1;
                    878:                                                        result=IN;
                    879:                                                        goto break2;
1.117     paf       880:                                                case 's': // is
1.95      paf       881:                                                        skip_analized=1;
                    882:                                                        result=IS;
                    883:                                                        goto break2;
                    884:                                                }
1.67      paf       885:                                        }
                    886:                                break;
                    887:                        case 'd':
                    888:                                if(end==begin) // right after whitespace
1.114     paf       889:                                        if(PC.source[0]=='e' && PC.source[1]=='f') { // def
1.67      paf       890:                                                skip_analized=2;
                    891:                                                result=DEF;
1.58      paf       892:                                                goto break2;
1.50      paf       893:                                        }
1.48      paf       894:                                break;
                    895:                        case ' ': case '\t': case '\n':
1.63      paf       896:                                if(end!=begin) { // there were a string after previous operator?
                    897:                                        result=0; // return that string
                    898:                                        goto break2;
1.48      paf       899:                                }
1.63      paf       900:                                // that's a leading|traling space or after-operator-space
                    901:                                // ignoring it
                    902:                                // reset piece 'begin' position & line
1.114     paf       903:                                begin=PC.source; // after whitespace char
                    904:                                begin_line=PC.line;
1.48      paf       905:                                continue;
1.1       paf       906:                        }
                    907:                        break;
                    908: 
1.10      paf       909:                // VARIABLE GET/PUT/WITH
1.166     parser    910:                case LS_VAR_NAME_SIMPLE_WITH_COLON: 
                    911:                case LS_VAR_NAME_SIMPLE_WITHOUT_COLON:
                    912:                case LS_EXPRESSION_VAR_NAME_WITH_COLON: 
                    913:                case LS_EXPRESSION_VAR_NAME_WITHOUT_COLON:
                    914:                        if(
                    915:                                PC.ls==LS_EXPRESSION_VAR_NAME_WITH_COLON ||
                    916:                                PC.ls==LS_EXPRESSION_VAR_NAME_WITHOUT_COLON) {
1.56      paf       917:                                // name in expr ends also before binary operators 
1.48      paf       918:                                switch(c) {
1.92      paf       919:                                case '-': 
1.48      paf       920:                                        pop_LS(PC);
1.114     paf       921:                                        PC.source--;  if(--PC.col<0) { PC.line--;  PC.col=-1; }
1.48      paf       922:                                        result=EON;
                    923:                                        goto break2;
                    924:                                }
                    925:                        }
1.166     parser    926:                        if(
                    927:                                PC.ls==LS_VAR_NAME_SIMPLE_WITHOUT_COLON ||
                    928:                                PC.ls==LS_EXPRESSION_VAR_NAME_WITHOUT_COLON) {
1.142     parser    929:                                // name already has ':', stop before next 
                    930:                                switch(c) {
                    931:                                case ':': 
                    932:                                        pop_LS(PC);
                    933:                                        PC.source--;  if(--PC.col<0) { PC.line--;  PC.col=-1; }
                    934:                                        result=EON;
                    935:                                        goto break2;
                    936:                                }
                    937:                        }
1.48      paf       938:                        switch(c) {
                    939:                        case 0:
                    940:                        case ' ': case '\t': case '\n':
                    941:                        case ';':
1.126     paf       942:                        case ']': case '}': case ')': 
                    943:                        case '"': case '\'':
1.139     parser    944:                        case '<': case '>':  // these stand for HTML brackets AND expression binary ops
1.92      paf       945:                        case '+': case '*': case '/': case '%': 
                    946:                        case '&': case '|': 
                    947:                        case '=': case '!':
1.99      paf       948:                        // common delimiters
1.158     parser    949:                        case ',': case '?':
1.139     parser    950:                        // before call
                    951:                        case '^': 
1.1       paf       952:                                pop_LS(PC);
1.114     paf       953:                                PC.source--;  if(--PC.col<0) { PC.line--;  PC.col=-1; }
1.13      paf       954:                                result=EON;
1.1       paf       955:                                goto break2;
1.48      paf       956:                        case '[':
1.162     parser    957:                                // $name.<[>code]
                    958:                                if(PC.col>1/*not first column*/ && (
1.163     parser    959:                                        end[-1]=='$'/*was start of get*/ ||
                    960:                                        end[-1]==':'/*was class name delim */ ||
                    961:                                        end[-1]=='.'/*was name delim */
1.162     parser    962:                                        )) {
1.166     parser    963:                                        push_LS(PC, LS_NAME_SQUARE_PART);
1.162     parser    964:                                        lexical_brackets_nestage=1;
                    965:                                        RC;
                    966:                                }
1.114     paf       967:                                PC.ls=LS_VAR_SQUARE;
1.1       paf       968:                                lexical_brackets_nestage=1;
1.48      paf       969:                                RC;
                    970:                        case '{':
                    971:                                if(begin==end) { // ${name}, no need of EON, switching LS
1.114     paf       972:                                        PC.ls=LS_VAR_NAME_CURLY; 
1.48      paf       973:                                } else {
1.114     paf       974:                                        PC.ls=LS_VAR_CURLY;
1.48      paf       975:                                        lexical_brackets_nestage=1;
                    976:                                }
1.69      paf       977: 
1.48      paf       978:                                RC;
                    979:                        case '(':
1.114     paf       980:                                PC.ls=LS_VAR_ROUND;
1.1       paf       981:                                lexical_brackets_nestage=1;
1.48      paf       982:                                RC;
                    983:                        case '.': // name part delim
                    984:                        case '$': // name part subvar
1.160     parser    985:                        case ':': // class<:>name
1.166     parser    986:                                // go to _WITHOUT_COLON state variant...
                    987:                                if(PC.ls==LS_VAR_NAME_SIMPLE_WITH_COLON)
                    988:                                        PC.ls=LS_VAR_NAME_SIMPLE_WITHOUT_COLON;
                    989:                                else if(PC.ls==LS_EXPRESSION_VAR_NAME_WITH_COLON)
                    990:                                        PC.ls=LS_EXPRESSION_VAR_NAME_WITHOUT_COLON;
                    991:                                // ...stop before next ':'
1.48      paf       992:                                RC;
1.1       paf       993:                        }
                    994:                        break;
1.48      paf       995: 
1.1       paf       996:                case LS_VAR_NAME_CURLY:
1.48      paf       997:                        switch(c) {
1.162     parser    998:                        case '[':
1.166     parser    999:                                // ${name.<[>code]}
                   1000:                                push_LS(PC, LS_NAME_SQUARE_PART);
1.160     parser   1001:                                lexical_brackets_nestage=1;
                   1002:                                RC;
1.48      paf      1003:                        case '}': // ${name} finished, restoring LS
1.1       paf      1004:                                pop_LS(PC);
1.48      paf      1005:                                RC;
                   1006:                        case '.': // name part delim
                   1007:                        case '$': // name part subvar
                   1008:                        case ':': // ':name' or 'class:name'
                   1009:                                RC;
1.1       paf      1010:                        }
                   1011:                        break;
1.48      paf      1012: 
                   1013:                case LS_VAR_SQUARE:
                   1014:                        switch(c) {
                   1015:                        case '$':
1.166     parser   1016:                                push_LS(PC, LS_VAR_NAME_SIMPLE_WITH_COLON);
1.48      paf      1017:                                RC;
                   1018:                        case '^':
1.10      paf      1019:                                push_LS(PC, LS_METHOD_NAME);
1.48      paf      1020:                                RC;
                   1021:                        case ']':
1.1       paf      1022:                                if(--lexical_brackets_nestage==0) {
                   1023:                                        pop_LS(PC);
1.48      paf      1024:                                        RC;
1.1       paf      1025:                                }
1.48      paf      1026:                                break;
                   1027:                        case ';': // operator_or_fmt;value delim
                   1028:                                RC;
                   1029:                        case '[':
                   1030:                                lexical_brackets_nestage++;
                   1031:                                break;
1.1       paf      1032:                        }
                   1033:                        break;
1.48      paf      1034: 
1.1       paf      1035:                case LS_VAR_CURLY:
1.48      paf      1036:                        switch(c) {
                   1037:                        case '$':
1.166     parser   1038:                                push_LS(PC, LS_VAR_NAME_SIMPLE_WITH_COLON);
1.48      paf      1039:                                RC;
                   1040:                        case '^':
1.10      paf      1041:                                push_LS(PC, LS_METHOD_NAME);
1.48      paf      1042:                                RC;
                   1043:                        case '}':
1.1       paf      1044:                                if(--lexical_brackets_nestage==0) {
                   1045:                                        pop_LS(PC);
1.48      paf      1046:                                        RC;
1.1       paf      1047:                                }
1.48      paf      1048:                                break;
                   1049:                        case '{':
1.1       paf      1050:                                lexical_brackets_nestage++;
1.48      paf      1051:                                break;
                   1052:                        }
1.1       paf      1053:                        break;
                   1054: 
1.10      paf      1055:                // METHOD CALL
1.1       paf      1056:                case LS_METHOD_NAME:
1.48      paf      1057:                        switch(c) {
                   1058:                        case '[':
1.166     parser   1059:                                // ^name.<[>code].xxx
1.162     parser   1060:                                if(PC.col>1/*not first column*/ && (
1.163     parser   1061:                                        end[-1]=='^'/*was start of call*/ || // never, ^[ is literal...
                   1062:                                        end[-1]==':'/*was class name delim */ ||
                   1063:                                        end[-1]=='.'/*was name delim */
1.162     parser   1064:                                        )) {
1.166     parser   1065:                                        push_LS(PC, LS_NAME_SQUARE_PART);
1.162     parser   1066:                                        lexical_brackets_nestage=1;
                   1067:                                        RC;
                   1068:                                }
1.114     paf      1069:                                PC.ls=LS_METHOD_SQUARE;
1.1       paf      1070:                                lexical_brackets_nestage=1;
1.48      paf      1071:                                RC;
                   1072:                        case '{':
1.114     paf      1073:                                PC.ls=LS_METHOD_CURLY;
1.1       paf      1074:                                lexical_brackets_nestage=1;
1.48      paf      1075:                                RC;
1.69      paf      1076:                        case '(':
1.114     paf      1077:                                PC.ls=LS_METHOD_ROUND;
1.69      paf      1078:                                lexical_brackets_nestage=1;
                   1079:                                RC;
1.48      paf      1080:                        case '.': // name part delim 
                   1081:                        case '$': // name part subvar
                   1082:                        case ':': // ':name' or 'class:name'
                   1083:                                RC;
1.1       paf      1084:                        }
                   1085:                        break;
1.48      paf      1086: 
                   1087:                case LS_METHOD_SQUARE:
                   1088:                        switch(c) {
                   1089:                        case '$':
1.166     parser   1090:                                push_LS(PC, LS_VAR_NAME_SIMPLE_WITH_COLON);
1.48      paf      1091:                                RC;
                   1092:                        case '^':
1.10      paf      1093:                                push_LS(PC, LS_METHOD_NAME);
1.48      paf      1094:                                RC;
                   1095:                        case ';': // param delim
                   1096:                                RC;
                   1097:                        case ']':
1.1       paf      1098:                                if(--lexical_brackets_nestage==0) {
1.114     paf      1099:                                        PC.ls=LS_METHOD_AFTER;
1.48      paf      1100:                                        RC;
1.1       paf      1101:                                }
1.48      paf      1102:                                break;
                   1103:                        case '[':
1.1       paf      1104:                                lexical_brackets_nestage++;
1.48      paf      1105:                                break;
                   1106:                        }
1.1       paf      1107:                        break;
1.48      paf      1108: 
1.1       paf      1109:                case LS_METHOD_CURLY:
1.48      paf      1110:                        switch(c) {
                   1111:                        case '$':
1.166     parser   1112:                                push_LS(PC, LS_VAR_NAME_SIMPLE_WITH_COLON);
1.48      paf      1113:                                RC;
                   1114:                        case '^':
1.10      paf      1115:                                push_LS(PC, LS_METHOD_NAME);
1.94      paf      1116:                                RC;
                   1117:                        case ';': // param delim
1.48      paf      1118:                                RC;
                   1119:                        case '}':
1.1       paf      1120:                                if(--lexical_brackets_nestage==0) {
1.114     paf      1121:                                        PC.ls=LS_METHOD_AFTER;
1.48      paf      1122:                                        RC;
1.1       paf      1123:                                }
1.48      paf      1124:                                break;
                   1125:                        case '{':
1.1       paf      1126:                                lexical_brackets_nestage++;
1.48      paf      1127:                                break;
                   1128:                        }
1.1       paf      1129:                        break;
1.48      paf      1130: 
1.1       paf      1131:                case LS_METHOD_AFTER:
1.69      paf      1132:                        if(c=='[') {/* ][ }[ )[ */
1.114     paf      1133:                                PC.ls=LS_METHOD_SQUARE;
1.1       paf      1134:                                lexical_brackets_nestage=1;
1.48      paf      1135:                                RC;
1.1       paf      1136:                        }                                          
1.69      paf      1137:                        if(c=='{') {/* ]{ }{ ){ */
1.114     paf      1138:                                PC.ls=LS_METHOD_CURLY;
1.69      paf      1139:                                lexical_brackets_nestage=1;
                   1140:                                RC;
                   1141:                        }                                          
                   1142:                        if(c=='(') {/* ]( }( )( */
1.114     paf      1143:                                PC.ls=LS_METHOD_ROUND;
1.1       paf      1144:                                lexical_brackets_nestage=1;
1.48      paf      1145:                                RC;
1.1       paf      1146:                        }                                          
                   1147:                        pop_LS(PC);
1.114     paf      1148:                        PC.source--;  if(--PC.col<0) { PC.line--;  PC.col=-1; }
1.13      paf      1149:                        result=EON;
1.1       paf      1150:                        goto break2;
                   1151:                }
1.9       paf      1152:                if(c==0) {
1.1       paf      1153:                        result=-1;
                   1154:                        break;
                   1155:                }
                   1156:        }
                   1157: 
                   1158: break2:
1.59      paf      1159:        if(end!=begin) { // there is last piece?
                   1160:                if((c=='@' || c==0) && end[-1]=='\n') { // we are before LS_DEF_NAME or EOF?
                   1161:                        // strip last \n
1.10      paf      1162:                        end--;
1.137     parser   1163:                        if(end!=begin && end[-1]=='\n') // allow one empty line before LS_DEF_NAME
                   1164:                                end--;
1.59      paf      1165:                }
1.133     parser   1166:                if(end!=begin && PC.ls!=LS_COMMENT) { // last piece still alive and not comment?
1.59      paf      1167:                        // append it
1.121     paf      1168:                        PC.string->APPEND_CLEAN(begin, end-begin, PC.file, begin_line/*, start_col*/);
1.30      paf      1169:                }
1.59      paf      1170:        }
1.114     paf      1171:        if(PC.string->size()) { // something accumulated?
1.17      paf      1172:                // create STRING value: array of OP_VALUE+vstring
1.114     paf      1173:                *lvalp=VL(NEW VString(*PC.string));
1.10      paf      1174:                // new pieces storage
1.114     paf      1175:                PC.string=NEW String(POOL);
1.58      paf      1176:                // make current result be pending for next call, return STRING for now
1.114     paf      1177:                PC.pending_state=result;  result=STRING;
1.58      paf      1178:        }
1.67      paf      1179:        if(skip_analized) {
1.114     paf      1180:                PC.source+=skip_analized;  PC.col+=skip_analized;
1.1       paf      1181:        }
1.58      paf      1182:        return result;
1.1       paf      1183: }
                   1184: 
1.110     paf      1185: static int real_yyerror(parse_control *pc, char *s) {  // Called by yyparse on error
1.114     paf      1186:           strncpy(PC.error, s, MAX_STRING);
1.1       paf      1187:           return 1;
1.110     paf      1188: }
1.1       paf      1189: 
1.110     paf      1190: static void yyprint(FILE *file, int type, YYSTYPE value) {
                   1191:        if(type==STRING)
1.120     paf      1192:                fprintf(file, " \"%s\"", LA2S(value)->cstr());
1.110     paf      1193: }

E-mail: