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

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

E-mail: