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

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

E-mail: