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

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

E-mail: