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

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

E-mail: