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

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

E-mail: