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

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

E-mail: