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

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

E-mail: