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

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

E-mail: