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

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

E-mail: