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

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

E-mail: