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

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

E-mail: