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

1.105     paf         1: /** @file
1.106     paf         2:        Parser: compiler(lexical parser and grammar).
                      3: 
1.87      paf         4:        Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.106     paf         5: 
1.89      paf         6:        Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
1.87      paf         7: 
1.125   ! paf         8:        $Id: compile.y,v 1.124.2.1 2001/04/16 11:26:42 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.1       paf        22: %{
1.90      paf        23: #define YYSTYPE  Array/*<Operation>*/ *
1.9       paf        24: #define YYPARSE_PARAM  pc
                     25: #define YYLEX_PARAM  pc
                     26: #define YYDEBUG  1
1.106     paf        27: #define YYERROR_VERBOSE        1
1.9       paf        28: #define yyerror(msg)  real_yyerror((parse_control *)pc, msg)
                     29: #define YYPRINT(file, type, value)  yyprint(file, type, value)
1.1       paf        30: 
1.108     paf        31: #include "pa_config_includes.h"
1.1       paf        32: #include <stdio.h>
                     33: #include <stdlib.h>
1.117     paf        34: #include <ctype.h>
1.1       paf        35: 
                     36: #include "compile_tools.h"
1.8       paf        37: #include "pa_value.h"
1.12      paf        38: #include "pa_request.h"
1.39      paf        39: #include "pa_vobject.h"
1.52      paf        40: #include "pa_vdouble.h"
1.98      paf        41: #include "pa_globals.h"
1.120     paf        42: #include "pa_vunknown.h"
1.39      paf        43: 
1.85      paf        44: #define SELF_ELEMENT_NAME "self"
1.97      paf        45: #define USE_CONTROL_METHOD_NAME "USE"
1.1       paf        46: 
1.125   ! paf        47: static int real_yyerror(parse_control *pc, char *s);
1.9       paf        48: static void yyprint(FILE *file, int type, YYSTYPE value);
1.125   ! paf        49: static int yylex(YYSTYPE *lvalp, void *pc);
1.1       paf        50: 
                     51: 
1.8       paf        52: // local convinient inplace typecast & var
1.114     paf        53: #define PC  (*(parse_control *)pc)
                     54: #define POOL  (*PC.pool)
1.25      paf        55: #undef NEW
                     56: #define NEW new(POOL)
1.107     paf        57: #ifndef DOXYGEN
1.1       paf        58: %}
                     59: 
                     60: %pure_parser
                     61: 
1.13      paf        62: %token EON
1.4       paf        63: %token STRING
1.1       paf        64: %token BOGUS
1.55      paf        65: 
1.58      paf        66: %token BAD_STRING_COMPARISON_OPERATOR
1.114     paf        67: %token BAD_HEX_LITERAL
1.58      paf        68: 
1.59      paf        69: %token LAND "&&"
1.58      paf        70: %token LOR "||"
1.59      paf        71: %token LXOR "##"
1.58      paf        72: 
                     73: %token NLE "<="
                     74: %token NGE ">="
                     75: %token NEQ "=="
                     76: %token NNE "!="
                     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.95      paf        88: %token IS "is"
1.67      paf        89: 
1.57      paf        90: /* logical */
1.95      paf        91: %left "is"
1.61      paf        92: %left "lt" "gt" "le" "ge"
                     93: %left "eq" "ne"
1.59      paf        94: %left '<' '>' "<=" ">=" "##"
1.57      paf        95: %left "==" "!="
                     96: %left "||"
                     97: %left "&&"
1.67      paf        98: %left "def" "in" "-f"
1.68      paf        99: %left '!'
1.57      paf       100: 
                    101: /* bitwise */
1.59      paf       102: %left '#'
1.57      paf       103: %left '&' '|'
1.68      paf       104: %left '~'
1.57      paf       105: 
1.56      paf       106: /* numerical */
1.55      paf       107: %left '-' '+'
1.57      paf       108: %left '*' '/' '%'
1.56      paf       109: %left NEG     /* negation: unary - */
1.1       paf       110: 
                    111: %%
1.88      paf       112: all:
1.10      paf       113:        one_big_piece {
1.75      paf       114:        Method& method=*NEW Method(POOL, 
1.85      paf       115:                *main_method_name, 
1.122     paf       116:                Method::CT_ANY,
1.81      paf       117:                0, 0, /*min, max numbered_params_count*/
1.75      paf       118:                0/*param_names*/, 0/*local_names*/, 
                    119:                $1/*parser_code*/, 0/*native_code*/);
1.114     paf       120:        PC.cclass->add_method(*main_method_name, method);
1.10      paf       121: }
                    122: |      methods;
                    123: 
                    124: methods: method | methods method;
                    125: one_big_piece: maybe_codes;
                    126: 
1.34      paf       127: method: control_method | code_method;
                    128: 
                    129: control_method: '@' STRING '\n' 
                    130:                                control_strings {
1.120     paf       131:        const String& command=*LA2S($2);
1.34      paf       132:        YYSTYPE strings_code=$4;
1.37      paf       133:        if(strings_code->size()<1*2) {
1.114     paf       134:                strcpy(PC.error, "@");
                    135:                strcat(PC.error, command.cstr());
                    136:                strcat(PC.error, " is empty");
1.37      paf       137:                YYERROR;
                    138:        }
1.74      paf       139:        if(command==CLASS_NAME) {
1.124     paf       140:                if(PC.cclass) { // already changed from default?
1.114     paf       141:                        strcpy(PC.error, "class already have a name '");
                    142:                        strncat(PC.error, PC.cclass->name().cstr(), 100);
                    143:                        strcat(PC.error, "'");
1.73      paf       144:                        YYERROR;
                    145:                }
                    146:                if(strings_code->size()==1*2) {
                    147:                        // new class' name
1.120     paf       148:                        const String *name=LA2S(strings_code);
1.73      paf       149:                        // creating the class
1.114     paf       150:                        PC.cclass=NEW VClass(POOL);
                    151:                        PC.cclass->set_name(*name);
1.73      paf       152:                        // append to request's classes
1.114     paf       153:                        PC.request->classes().put(*name, PC.cclass);
1.73      paf       154:                } else {
1.114     paf       155:                        strcpy(PC.error, "@"CLASS_NAME" must contain sole name");
1.34      paf       156:                        YYERROR;
                    157:                }
                    158:        } else {
1.85      paf       159:                if(command==USE_CONTROL_METHOD_NAME) {
1.109     paf       160:                        for(int i=0; i<strings_code->size(); i+=2) 
1.114     paf       161:                                PC.request->use_file(
1.120     paf       162:                                        PC.request->absolute(*LA2S(strings_code, i)));
1.74      paf       163:                } else if(command==BASE_NAME) {
1.124     paf       164:                        if(PC.cclass->base()) { // already changed from default?
1.114     paf       165:                                strcpy(PC.error, "class already have a base '");
                    166:                                strncat(PC.error, PC.cclass->base()->name().cstr(), 100);
                    167:                                strcat(PC.error, "'");
1.73      paf       168:                                YYERROR;
                    169:                        }
1.45      paf       170:                        if(strings_code->size()==1*2) {
1.120     paf       171:                                const String& base_name=*LA2S(strings_code);
1.45      paf       172:                                VClass *base=static_cast<VClass *>(
1.114     paf       173:                                        PC.request->classes().get(base_name));
1.45      paf       174:                                if(!base) {
1.114     paf       175:                                        strcpy(PC.error, base_name.cstr());
                    176:                                        strcat(PC.error, ": undefined class in @"BASE_NAME);
1.109     paf       177:                                        YYERROR;
                    178:                                }
                    179:                                // @CLASS == @BASE sanity check
1.114     paf       180:                                if(PC.cclass==base) {
                    181:                                        strcpy(PC.error, "@"CLASS_NAME" equals @"BASE_NAME);
1.34      paf       182:                                        YYERROR;
                    183:                                }
1.114     paf       184:                                PC.cclass->set_base(*base);
1.45      paf       185:                        } else {
1.114     paf       186:                                strcpy(PC.error, "@"BASE_NAME" must contain sole name");
1.45      paf       187:                                YYERROR;
1.34      paf       188:                        }
                    189:                } else {
1.114     paf       190:                        strcpy(PC.error, "'");
                    191:                        strncat(PC.error, command.cstr(), MAX_STRING/2);
                    192:                        strcat(PC.error, "' invalid special name. valid names are "
1.92      paf       193:                                "'"CLASS_NAME"', '"USE_CONTROL_METHOD_NAME"' and '"BASE_NAME"'");
1.34      paf       194:                        YYERROR;
                    195:                }
                    196:        }
                    197: };
1.37      paf       198: control_strings: control_string | control_strings control_string { $$=$1; P($$, $2) };
                    199: control_string: maybe_string '\n';
                    200: maybe_string: empty | STRING;
1.34      paf       201: 
                    202: code_method: '@' STRING bracketed_maybe_strings maybe_bracketed_strings maybe_comment '\n' 
1.10      paf       203:                        maybe_codes {
1.120     paf       204:        const String *name=LA2S($2);
1.10      paf       205: 
                    206:        YYSTYPE params_names_code=$3;
1.75      paf       207:        Array *params_names=0;
                    208:        if(int size=params_names_code->size()) {
                    209:                params_names=NEW Array(POOL);
                    210:                for(int i=0; i<size; i+=2)
1.120     paf       211:                        *params_names+=LA2S(params_names_code, i);
1.75      paf       212:        }
1.10      paf       213: 
                    214:        YYSTYPE locals_names_code=$4;
1.75      paf       215:        Array *locals_names=0;
                    216:        if(int size=locals_names_code->size()) {
                    217:                locals_names=NEW Array(POOL);
                    218:                for(int i=0; i<size; i+=2)
1.120     paf       219:                        *locals_names+=LA2S(locals_names_code, i);
1.75      paf       220:        }
1.10      paf       221: 
1.76      paf       222:        Method& method=*NEW Method(POOL, 
                    223:                *name, 
1.122     paf       224:                Method::CT_ANY,
1.81      paf       225:                0, 0/*min,max numbered_params_count*/, 
1.76      paf       226:                params_names, locals_names, 
                    227:                $7, 0);
1.114     paf       228:        PC.cclass->add_method(*name, method);
1.8       paf       229: };
1.10      paf       230: 
                    231: maybe_bracketed_strings: empty | bracketed_maybe_strings;
                    232: bracketed_maybe_strings: '[' maybe_strings ']' {$$=$2};
                    233: maybe_strings: empty | strings;
                    234: strings: STRING | strings ';' STRING { $$=$1; P($$, $3) };
                    235: 
                    236: maybe_comment: empty | STRING;
1.1       paf       237: 
                    238: /* codes */
                    239: 
1.10      paf       240: maybe_codes: empty | codes;
                    241: 
1.90      paf       242: codes: code | codes code { $$=$1; P($$, $2) };
1.81      paf       243: code: write_string | action;
1.1       paf       244: action: get | put | with | call;
                    245: 
                    246: /* get */
                    247: 
1.64      paf       248: get: get_value {
                    249:        $$=$1; /* stack: resulting value */
1.102     paf       250:        O($$, OP_WRITE_VALUE); /* value=pop; wcontext.write(value) */
1.1       paf       251: };
1.64      paf       252: get_value: '$' get_name_value { $$=$2 }
                    253: get_name_value: name_without_curly_rdive EON | name_in_curly_rdive;
1.1       paf       254: name_in_curly_rdive: '{' name_without_curly_rdive '}' { $$=$2 };
1.44      paf       255: name_without_curly_rdive: 
                    256:        name_without_curly_rdive_read 
                    257: |      name_without_curly_rdive_root
                    258: |      name_without_curly_rdive_class;
1.19      paf       259: name_without_curly_rdive_read: name_without_curly_rdive_code {
1.25      paf       260:        $$=N(POOL); 
1.22      paf       261:        Array *diving_code=$1;
1.120     paf       262:        const String *first_name=LA2S(diving_code);
1.85      paf       263:        if(first_name && *first_name==SELF_ELEMENT_NAME) {
1.54      paf       264:                O($$, OP_WITH_SELF); /* stack: starting context */
1.22      paf       265:                P($$, diving_code, 
                    266:                        /* skip over... */
                    267:                        diving_code->size()>2?3/*OP_+string+get_element*/:2/*OP_+string*/);
                    268:        } else {
1.54      paf       269:                O($$, OP_WITH_READ); /* stack: starting context */
1.22      paf       270:                P($$, diving_code);
                    271:        }
                    272:        /* diving code; stack: current context */
1.1       paf       273: };
1.19      paf       274: name_without_curly_rdive_root: ':' name_without_curly_rdive_code {
1.25      paf       275:        $$=N(POOL); 
1.54      paf       276:        O($$, OP_WITH_ROOT); /* stack: starting context */
1.19      paf       277:        P($$, $2); /* diving code; stack: current context */
                    278: };
1.44      paf       279: name_without_curly_rdive_class: class_prefix name_without_curly_rdive_code { $$=$1; P($$, $2) };
1.19      paf       280: name_without_curly_rdive_code: name_advance2 | name_path name_advance2 { $$=$1; P($$, $2) };
1.1       paf       281: 
                    282: /* put */
                    283: 
1.81      paf       284: put: '$' name_expr_wdive construct {
1.20      paf       285:        $$=$2; /* stack: context,name */
1.52      paf       286:        P($$, $3); /* stack: context,name,constructor_value */
1.20      paf       287: };
1.44      paf       288: name_expr_wdive: 
                    289:        name_expr_wdive_write
                    290: |      name_expr_wdive_root
                    291: |      name_expr_wdive_class;
1.28      paf       292: name_expr_wdive_write: name_expr_dive_code {
1.44      paf       293:        $$=N(POOL);
1.23      paf       294:        Array *diving_code=$1;
1.120     paf       295:        const String *first_name=LA2S(diving_code);
1.85      paf       296:        if(first_name && *first_name==SELF_ELEMENT_NAME) {
1.54      paf       297:                O($$, OP_WITH_SELF); /* stack: starting context */
1.23      paf       298:                P($$, diving_code, 
                    299:                        /* skip over... */
                    300:                        diving_code->size()>2?3/*OP_+string+get_element*/:2/*OP_+string*/);
                    301:        } else {
1.54      paf       302:                O($$, OP_WITH_WRITE); /* stack: starting context */
1.23      paf       303:                P($$, diving_code);
                    304:        }
                    305:        /* diving code; stack: current context */
1.20      paf       306: };
1.28      paf       307: name_expr_wdive_root: ':' name_expr_dive_code {
1.25      paf       308:        $$=N(POOL); 
1.54      paf       309:        O($$, OP_WITH_ROOT); /* stack: starting context */
1.9       paf       310:        P($$, $2); /* diving code; stack: context,name */
1.1       paf       311: };
1.44      paf       312: name_expr_wdive_class: class_prefix name_expr_dive_code { $$=$1; P($$, $2) };
1.20      paf       313: 
1.81      paf       314: construct: construct_by_code | construct_by_expr;
                    315: construct_by_code: '[' any_constructor_code_value ']' {
                    316:        $$=$2; /* stack: context, name, value */
                    317:        O($$, OP_CONSTRUCT_VALUE); /* value=pop; name=pop; context=pop; construct(context,name,value) */
                    318: }
                    319: ;
1.90      paf       320: construct_by_expr: '(' expr_value ')' { 
1.81      paf       321:        $$=$2; /* stack: context, name, value */
                    322:        O($$, OP_CONSTRUCT_EXPR); /* value=pop; name=pop; context=pop; construct(context,name,value) */
                    323: }
1.52      paf       324: ;
1.55      paf       325: any_constructor_code_value: 
1.120     paf       326:        unknown_value /* optimized $var[] case */
1.52      paf       327: |      STRING /* optimized $var[STRING] case */
1.55      paf       328: |      constructor_code_value /* $var[something complex] */
1.1       paf       329: ;
1.55      paf       330: constructor_code_value: constructor_code {
1.25      paf       331:        $$=N(POOL); 
1.54      paf       332:        O($$, OP_CREATE_EWPOOL); /* stack: empty write context */
1.69      paf       333:        P($$, $1); /* some code that writes to that context */
1.54      paf       334:        O($$, OP_REDUCE_EWPOOL); /* context=pop; stack: context.value() */
1.1       paf       335: };
1.55      paf       336: constructor_code: codes__excluding_sole_str_literal;
1.27      paf       337: codes__excluding_sole_str_literal: action | code codes { $$=$1; P($$, $2) };
                    338: 
1.1       paf       339: /* call */
                    340: 
1.66      paf       341: call: call_value {
                    342:        $$=$1; /* stack: value */
1.102     paf       343:        O($$, OP_WRITE_VALUE); /* value=pop; wcontext.write(value) */
1.66      paf       344: };
                    345: call_value: '^' call_name store_params EON { /* ^field.$method{vasya} */
1.42      paf       346:        $$=$2; /* with_xxx,diving code; stack: context,method_junction */
1.54      paf       347:        O($$, OP_GET_METHOD_FRAME); /* stack: context,method_frame */
1.123     paf       348: 
                    349:        YYSTYPE params_code=$3;
                    350:        if(params_code->size()==3) // probably [] case. [OP_VALUE + Unknown + STORE_PARAM]
                    351:                if(Value *value=LA2V(params_code)) // it is OP_VALUE + value?
                    352:                        if(!value->is_defined()) // value is VUnknown?
                    353:                                params_code=0; // ^zzz[] case. don't append lone empty param.
                    354:        if(params_code)
                    355:                P($$, params_code); // filling method_frame.store_params
                    356:        O($$, OP_CALL); // method_frame=pop; ncontext=pop; call(ncontext,method_frame) stack: value
1.1       paf       357: };
                    358: 
1.43      paf       359: call_name: name_without_curly_rdive;
1.38      paf       360: 
1.9       paf       361: store_params: store_param | store_params store_param { $$=$1; P($$, $2) };
1.69      paf       362: store_param: 
                    363:        store_square_param
                    364: |      store_round_param
                    365: |      store_curly_param
1.31      paf       366: ;
1.123     paf       367: store_square_param: '[' store_code_param_parts ']' {$$=$2};
1.69      paf       368: store_round_param: '(' store_expr_param_parts ')' {$$=$2};
1.94      paf       369: store_curly_param: '{' store_curly_param_parts '}' {$$=$2};
1.69      paf       370: store_code_param_parts:
                    371:        store_code_param_part
                    372: |      store_code_param_parts ';' store_code_param_part { $$=$1; P($$, $3) }
                    373: ;
                    374: store_expr_param_parts:
                    375:        store_expr_param_part
                    376: |      store_expr_param_parts ';' store_expr_param_part { $$=$1; P($$, $3) }
                    377: ;
1.94      paf       378: store_curly_param_parts:
                    379:        store_curly_param_part
                    380: |      store_curly_param_parts ';' store_curly_param_part { $$=$1; P($$, $3) }
                    381: ;
1.120     paf       382: store_code_param_part: code_param_value {
1.32      paf       383:        $$=$1;
1.54      paf       384:        O($$, OP_STORE_PARAM);
1.120     paf       385: };
1.69      paf       386: store_expr_param_part: write_expr_value {
                    387:        $$=N(POOL); 
1.103     paf       388:        PEA($$, $1);
1.69      paf       389: };
1.94      paf       390: store_curly_param_part: maybe_codes {
                    391:        $$=N(POOL); 
                    392:        PCA($$, $1);
                    393: };
1.120     paf       394: code_param_value:
                    395:        unknown_value /* optimized [;...] case */
                    396: |      STRING /* optimized [STRING] case */
                    397: |      constructor_code_value /* [something complex] */
                    398: ;
1.90      paf       399: write_expr_value: expr_value {
1.69      paf       400:        $$=$1;
1.102     paf       401:        O($$, OP_WRITE_EXPR_RESULT);
1.69      paf       402: };
1.1       paf       403: 
                    404: /* name */
                    405: 
1.20      paf       406: name_expr_dive_code: name_expr_value | name_path name_expr_value { $$=$1; P($$, $2) };
1.1       paf       407: 
1.9       paf       408: name_path: name_step | name_path name_step { $$=$1; P($$, $2) };
1.1       paf       409: name_step: name_advance1 '.';
                    410: name_advance1: name_expr_value {
                    411:        /* stack: context */
                    412:        $$=$1; /* stack: context,name */
1.54      paf       413:        O($$, OP_GET_ELEMENT); /* name=pop; context=pop; stack: context.get_element(name) */
1.1       paf       414: };
                    415: name_advance2: name_expr_value {
                    416:        /* stack: context */
                    417:        $$=$1; /* stack: context,name */
1.54      paf       418:        O($$, OP_GET_ELEMENT); /* name=pop; context=pop; stack: context.get_element(name) */
1.1       paf       419: }
1.4       paf       420: |      STRING BOGUS
1.1       paf       421: ;
                    422: name_expr_value: 
1.4       paf       423:        STRING /* subname_is_const */
1.1       paf       424: |      name_expr_subvar_value /* $subname_is_var_value */
                    425: |      name_expr_with_subvar_value /* xxx$part_of_subname_is_var_value[$...] */
                    426: ;
                    427: name_expr_subvar_value: '$' subvar_ref_name_rdive {
                    428:        $$=$2;
1.54      paf       429:        O($$, OP_GET_ELEMENT);
1.1       paf       430: };
1.4       paf       431: name_expr_with_subvar_value: STRING subvar_get_writes {
1.25      paf       432:        $$=N(POOL); 
1.54      paf       433:        O($$, OP_CREATE_EWPOOL);
1.9       paf       434:        P($$, $1);
1.102     paf       435:        O($$, OP_WRITE_VALUE);
1.9       paf       436:        P($$, $2);
1.54      paf       437:        O($$, OP_REDUCE_EWPOOL);
1.1       paf       438: };
1.18      paf       439: subvar_ref_name_rdive: subvar_ref_name_rdive_read | subvar_ref_name_rdive_root;
                    440: subvar_ref_name_rdive_read: STRING {
1.25      paf       441:        $$=N(POOL); 
1.54      paf       442:        O($$, OP_WITH_READ);
1.9       paf       443:        P($$, $1);
1.1       paf       444: };
1.18      paf       445: subvar_ref_name_rdive_root: ':' STRING {
1.25      paf       446:        $$=N(POOL); 
1.54      paf       447:        O($$, OP_WITH_ROOT);
1.18      paf       448:        P($$, $2);
                    449: };
1.9       paf       450: subvar_get_writes: subvar__get_write | subvar_get_writes subvar__get_write { $$=$1; P($$, $2) };
1.1       paf       451: subvar__get_write: '$' subvar_ref_name_rdive {
                    452:        $$=$2;
1.54      paf       453:        O($$, OP_GET_ELEMENT__WRITE);
1.42      paf       454: };
                    455: 
1.44      paf       456: class_prefix: STRING ':' {
1.72      paf       457:        $$=$1; // stack: class name string
                    458:        O($$, OP_GET_CLASS);
1.1       paf       459: };
                    460: 
                    461: 
                    462: /* with */
                    463: 
                    464: with: '$' name_without_curly_rdive '{' codes '}' {
                    465:        $$=$2;
1.54      paf       466:        O($$, OP_CREATE_RWPOOL);
1.9       paf       467:        P($$, $4);
1.54      paf       468:        O($$, OP_REDUCE_RWPOOL);
1.102     paf       469:        O($$, OP_WRITE_VALUE);
1.1       paf       470: };
1.53      paf       471: 
1.56      paf       472: /* expr */
1.53      paf       473: 
1.81      paf       474: expr_value: expr {
                    475:        if(($$=$1)->size()==2) // only one string literal in there?
1.62      paf       476:                change_string_literal_to_double_literal($$); // make that string literal Double
                    477: };
1.56      paf       478: expr: 
1.62      paf       479:        STRING
1.64      paf       480: |      get_value
1.66      paf       481: |      call_value
1.64      paf       482: |      '"' string_inside_quotes_value '"' { $$ = $2; }
1.60      paf       483: |      '(' expr ')' { $$ = $2; }
                    484: /* stack: operand // stack: @operand */
                    485: |      '-' expr %prec NEG { $$=$2;  O($$, OP_NEG) }
1.68      paf       486: |      '~' expr { $$=$2;        O($$, OP_INV) }
                    487: |      '!' expr { $$=$2;  O($$, OP_NOT) }
                    488: |      "def" expr { $$=$2;  O($$, OP_DEF) }
                    489: |      "in" expr { $$=$2;  O($$, OP_IN) }
                    490: |      "-f" expr { $$=$2;  O($$, OP_FEXISTS) }
1.60      paf       491: /* stack: a,b // stack: a@b */
                    492: |      expr '-' expr { $$=$1;  P($$, $3);  O($$, OP_SUB) }
                    493: |      expr '+' expr { $$=$1;  P($$, $3);  O($$, OP_ADD) }
                    494: |      expr '*' expr { $$=$1;  P($$, $3);  O($$, OP_MUL) }
                    495: |      expr '/' expr { $$=$1;  P($$, $3);  O($$, OP_DIV) }
                    496: |      expr '%' expr { $$=$1;  P($$, $3);  O($$, OP_MOD) }
                    497: |      expr '&' expr { $$=$1;  P($$, $3);  O($$, OP_BIN_AND) }
                    498: |      expr '|' expr { $$=$1;  P($$, $3);  O($$, OP_BIN_OR) }
                    499: |      expr '#' expr { $$=$1;  P($$, $3);  O($$, OP_BIN_XOR) }
                    500: |      expr "&&" expr { $$=$1;  P($$, $3);  O($$, OP_LOG_AND) }
                    501: |      expr "||" expr { $$=$1;  P($$, $3);  O($$, OP_LOG_OR) }
                    502: |      expr "##" expr { $$=$1;  P($$, $3);  O($$, OP_LOG_XOR) }
                    503: |      expr '<' expr { $$=$1;  P($$, $3);  O($$, OP_NUM_LT) }
                    504: |      expr '>' expr { $$=$1;  P($$, $3);  O($$, OP_NUM_GT) }
                    505: |      expr "<=" expr { $$=$1;  P($$, $3);  O($$, OP_NUM_LE) }
                    506: |      expr ">=" expr { $$=$1;  P($$, $3);  O($$, OP_NUM_GE) }
                    507: |      expr "==" expr { $$=$1;  P($$, $3);  O($$, OP_NUM_EQ) }
                    508: |      expr "!=" expr { $$=$1;  P($$, $3);  O($$, OP_NUM_NE) }
1.61      paf       509: |      expr "lt" expr { $$=$1;  P($$, $3);  O($$, OP_STR_LT) }
                    510: |      expr "gt" expr { $$=$1;  P($$, $3);  O($$, OP_STR_GT) }
                    511: |      expr "le" expr { $$=$1;  P($$, $3);  O($$, OP_STR_LE) }
                    512: |      expr "ge" expr { $$=$1;  P($$, $3);  O($$, OP_STR_GE) }
                    513: |      expr "eq" expr { $$=$1;  P($$, $3);  O($$, OP_STR_EQ) }
                    514: |      expr "ne" expr { $$=$1;  P($$, $3);  O($$, OP_STR_NE) }
1.95      paf       515: |      expr "is" expr { $$=$1;  P($$, $3);  O($$, OP_IS) }
1.56      paf       516: ;
1.55      paf       517: 
1.65      paf       518: string_inside_quotes_value: maybe_codes {
1.64      paf       519:        $$=N(POOL);
                    520:        O($$, OP_CREATE_SWPOOL); /* stack: empty write context */
1.69      paf       521:        P($$, $1); /* some code that writes to that context */
1.64      paf       522:        O($$, OP_REDUCE_SWPOOL); /* context=pop; stack: context.get_string() */
1.53      paf       523: };
1.1       paf       524: 
1.27      paf       525: /* basics */
1.1       paf       526: 
1.81      paf       527: write_string: STRING {
1.102     paf       528:        // optimized from OP_STRING+OP_WRITE_VALUE to OP_STRING__WRITE
1.84      paf       529:        change_string_literal_to_write_string_literal($$=$1)
1.54      paf       530: };
                    531: 
1.120     paf       532: unknown_value: /* empty */ { $$=VL(NEW VUnknown(POOL)) };
1.25      paf       533: empty: /* empty */ { $$=N(POOL) };
1.1       paf       534: 
                    535: %%
1.105     paf       536: #endif
1.1       paf       537: 
                    538: /*
                    539:        000$111(2222)00 
                    540:                000$111{3333}00
1.9       paf       541:        $,^: push,=0
1.1       paf       542:        1:( { break=pop
                    543:        2:( )  pop
                    544:        3:{ }  pop
                    545: 
                    546:        000^111(2222)4444{33333}4000
1.9       paf       547:        $,^: push,=0
1.1       paf       548:        1:( { break=pop
                    549:        2:( )=4
                    550:        3:{ }=4
                    551:                4:[^({]=pop
                    552: */
                    553: 
1.110     paf       554: static int yylex(YYSTYPE *lvalp, void *pc) {
1.114     paf       555:        #define lexical_brackets_nestage PC.brackets_nestages[PC.sp]
1.48      paf       556:        #define RC {result=c; goto break2; }
1.1       paf       557: 
                    558:     register int c;
                    559:     int result;
                    560:        
1.114     paf       561:        if(PC.pending_state) {
                    562:                result=PC.pending_state;
                    563:                PC.pending_state=0;
1.1       paf       564:                return result;
                    565:        }
                    566:        
1.114     paf       567:        const char *begin=PC.source;
1.91      paf       568:        const char *end;
1.114     paf       569:        int begin_line=PC.line;
1.67      paf       570:        int skip_analized=0;
1.50      paf       571:        while(true) {
1.114     paf       572:                c=*(end=(PC.source++));
1.1       paf       573: 
1.4       paf       574:                if(c=='\n') {
1.114     paf       575:                        PC.line++;
                    576:                        PC.col=0;
1.10      paf       577:                } else
1.114     paf       578:                        PC.col++;
1.73      paf       579: 
1.119     paf       580:                if(c=='^' && PC.ls!=LS_COMMENT && PC.ls!=LS_DEF_COMMENT) 
1.114     paf       581:                        switch(*PC.source) {
                    582:                        // escaping: ^^ ^$ ^; ^) ^} ^( ^{ ^"
1.48      paf       583:                        case '^': case '$': case ';':
                    584:                        case '[': case ']':
                    585:                        case '{': case '}':
1.114     paf       586:                        case '"': 
1.40      paf       587:                                if(end!=begin) {
                    588:                                        // append piece till ^
1.121     paf       589:                                        PC.string->APPEND_CLEAN(begin, end-begin, PC.file, begin_line);
1.40      paf       590:                                }
1.63      paf       591:                                // reset piece 'begin' position & line
1.114     paf       592:                                begin=PC.source; // ^
                    593:                                begin_line=PC.line;
1.40      paf       594:                                // skip over ^ and _
1.114     paf       595:                                PC.source++;  PC.col++;
1.40      paf       596:                                // skip analysis = forced literal
1.1       paf       597:                                continue;
1.114     paf       598: 
                    599:                        // converting ^#HH into char(hex(HH))
                    600:                        case '#':
                    601:                                if(end!=begin) {
                    602:                                        // append piece till ^
1.121     paf       603:                                        PC.string->APPEND_CLEAN(begin, end-begin, PC.file, begin_line);
1.114     paf       604:                                }
                    605:                                // #HH ?
                    606:                                if(PC.source[0]=='#' && PC.source[1] && PC.source[2]) {
                    607:                                        char *hex=(char *)POOL.malloc(1);
                    608:                                        hex[0]=
                    609:                                                hex_value[(unsigned char)PC.source[1]]*0x10+
                    610:                                                hex_value[(unsigned char)PC.source[2]];
                    611:                                        if(hex[0]==0) {
                    612:                                                result=BAD_HEX_LITERAL;
                    613:                                                goto break2; // wrong hex value[no ^#00 chars allowed]: bail out
                    614:                                        }
                    615:                                        // append char(hex(HH))
1.121     paf       616:                                        PC.string->APPEND_CLEAN(hex, 1, PC.file, begin_line);
1.114     paf       617:                                        // skip over ^#HH
                    618:                                        PC.source+=3;
                    619:                                        PC.col+=3;
                    620:                                        // reset piece 'begin' position & line
                    621:                                        begin=PC.source; // ^
                    622:                                        begin_line=PC.line;
                    623:                                        continue;
                    624:                                }
                    625:                                break;
1.1       paf       626:                        }
1.113     paf       627:                // #comment  start skipping
1.114     paf       628:                if(c=='#' && PC.col==1) {
1.112     paf       629:                        if(end!=begin) {
                    630:                                // append piece till #
1.121     paf       631:                                PC.string->APPEND_CLEAN(begin, end-begin, PC.file, begin_line);
1.112     paf       632:                        }
                    633:                        // fall into COMMENT lexical state [wait for \n]
                    634:                        push_LS(PC, LS_COMMENT);
                    635:                }
1.114     paf       636:                switch(PC.ls) {
1.10      paf       637: 
                    638:                // USER'S = NOT OURS
1.1       paf       639:                case LS_USER:
1.48      paf       640:                        switch(c) {
                    641:                        case '$':
1.10      paf       642:                                push_LS(PC, LS_VAR_NAME_SIMPLE);
1.48      paf       643:                                RC;
                    644:                        case '^':
                    645:                                push_LS(PC, LS_METHOD_NAME);
                    646:                                RC;
                    647:                        case '@':
1.114     paf       648:                                if(PC.col==0+1) {
1.48      paf       649:                                        push_LS(PC, LS_DEF_NAME);
                    650:                                        RC;
                    651:                                }
                    652:                                break;
1.112     paf       653:                        }
                    654:                        break;
                    655:                        
                    656:                // #COMMENT
                    657:                case LS_COMMENT:
                    658:                        if(c=='\n') {
                    659:                                // skip comment
1.114     paf       660:                                begin=PC.source;
                    661:                                begin_line=PC.line;
1.112     paf       662: 
                    663:                                pop_LS(PC);
                    664:                                continue;
1.1       paf       665:                        }
1.48      paf       666:                        break;
                    667:                        
                    668:                // STRING IN EXPRESSION
                    669:                case LS_EXPRESSION_STRING:
                    670:                        switch(c) {
                    671:                        case '"':
                    672:                                pop_LS(PC); //"abc".
                    673:                                RC;
                    674:                        case '$':
                    675:                                push_LS(PC, LS_VAR_NAME_SIMPLE);
                    676:                                RC;
                    677:                        case '^':
1.10      paf       678:                                push_LS(PC, LS_METHOD_NAME);
1.48      paf       679:                                RC;
1.10      paf       680:                        }
                    681:                        break;
                    682: 
                    683:                // METHOD DEFINITION
                    684:                case LS_DEF_NAME:
1.48      paf       685:                        switch(c) {
                    686:                        case '[':
1.114     paf       687:                                PC.ls=LS_DEF_PARAMS;
1.48      paf       688:                                RC;
                    689:                        case '\n':
1.114     paf       690:                                PC.ls=LS_DEF_SPECIAL_BODY;
1.48      paf       691:                                RC;
1.10      paf       692:                        }
                    693:                        break;
1.48      paf       694: 
1.10      paf       695:                case LS_DEF_PARAMS:
1.48      paf       696:                        switch(c) {
                    697:                        case ';':
                    698:                                RC;
                    699:                        case ']':
1.114     paf       700:                                PC.ls=*PC.source=='['?LS_DEF_LOCALS:LS_DEF_COMMENT;
1.48      paf       701:                                RC;
1.49      paf       702:                        case '\n': // wrong. bailing out
1.10      paf       703:                                pop_LS(PC);
1.48      paf       704:                                RC;
1.10      paf       705:                        }
                    706:                        break;
1.48      paf       707: 
1.10      paf       708:                case LS_DEF_LOCALS:
1.48      paf       709:                        switch(c) {
                    710:                        case '[':
                    711:                        case ';':
                    712:                                RC;
                    713:                        case ']':
1.114     paf       714:                                PC.ls=LS_DEF_COMMENT;
1.48      paf       715:                                RC;
                    716:                        case '\n': // wrong. bailing out
1.10      paf       717:                                pop_LS(PC);
1.48      paf       718:                                RC;
1.10      paf       719:                        }
                    720:                        break;
1.48      paf       721: 
1.10      paf       722:                case LS_DEF_COMMENT:
                    723:                        if(c=='\n') {
                    724:                                pop_LS(PC);
1.48      paf       725:                                RC;
1.37      paf       726:                        }
                    727:                        break;
                    728: 
1.48      paf       729:                case LS_DEF_SPECIAL_BODY:
1.37      paf       730:                        if(c=='\n') {
1.114     paf       731:                                switch(*PC.source) {
1.48      paf       732:                                case '@': case 0: // end of special_code
1.37      paf       733:                                        pop_LS(PC);
1.48      paf       734:                                        break;
                    735:                                }
                    736:                                RC;
                    737:                        }
                    738:                        break;
                    739: 
                    740:                // (EXPRESSION)
1.69      paf       741:                case LS_VAR_ROUND:
                    742:                case LS_METHOD_ROUND:
1.48      paf       743:                        switch(c) {
                    744:                        case ')':
                    745:                                if(--lexical_brackets_nestage==0)
1.114     paf       746:                                        if(PC.ls==LS_METHOD_ROUND) // method round param ended
                    747:                                                PC.ls=LS_METHOD_AFTER; // look for method end
                    748:                                        else // PC.ls==LS_VAR_ROUND // variable constructor ended
1.69      paf       749:                                                pop_LS(PC); // return to normal life
1.48      paf       750:                                RC;
                    751:                        case '$':
1.69      paf       752:                                push_LS(PC, LS_EXPRESSION_VAR_NAME);                            
1.48      paf       753:                                RC;
                    754:                        case '^':
                    755:                                push_LS(PC, LS_METHOD_NAME);
                    756:                                RC;
                    757:                        case '(':
                    758:                                lexical_brackets_nestage++;
                    759:                                RC;
1.67      paf       760:                        case '-':
1.114     paf       761:                                if(*PC.source=='f') { // -f
1.67      paf       762:                                        skip_analized=1;
                    763:                                        result=FEXISTS;
                    764:                                } else
                    765:                                        result=c;
                    766:                                goto break2;
                    767:                        case '+': case '*': case '/': case '%': 
1.58      paf       768:                        case '~':
1.48      paf       769:                        case ';':
                    770:                                RC;
1.59      paf       771:                        case '&': case '|':  case '#':
1.114     paf       772:                                if(*PC.source==c) { // && ||
1.59      paf       773:                                        result=c=='#'?LXOR:c=='&'?LAND:LOR;
1.67      paf       774:                                        skip_analized=1;
1.58      paf       775:                                } else
                    776:                                        result=c;
                    777:                                goto break2;
                    778:                        case '<': case '>': case '=': case '!': 
1.114     paf       779:                                if(*PC.source=='=') { // <= >= == !=
1.67      paf       780:                                        skip_analized=1;
1.58      paf       781:                                        switch(c) {
                    782:                                        case '<': result=NLE; break;
                    783:                                        case '>': result=NGE; break;
                    784:                                        case '=': result=NEQ; break;
                    785:                                        case '!': result=NNE; break;
                    786:                                        }
                    787:                                } else
                    788:                                        result=c;
                    789:                                goto break2;
1.48      paf       790:                        case '"':
                    791:                                push_LS(PC, LS_EXPRESSION_STRING);
                    792:                                RC;
1.50      paf       793:                        case 'l': case 'g': case 'e': case 'n':
1.51      paf       794:                                if(end==begin) // right after whitespace
1.117     paf       795:                                        if(isspace(PC.source[1])) {
                    796:                                                switch(*PC.source) {
                    797:                                                        //                                      case '?': // ok [and bad cases, yacc would bark at them]
                    798:                                                case 't': // lt gt [et nt]
                    799:                                                        result=c=='l'?SLT:c=='g'?SGT:BAD_STRING_COMPARISON_OPERATOR;
                    800:                                                        skip_analized=1;
                    801:                                                        goto break2;
                    802:                                                case 'e': // le ge ne [ee]
                    803:                                                        result=c=='l'?SLE:c=='g'?SGE:c=='n'?SNE:BAD_STRING_COMPARISON_OPERATOR;
                    804:                                                        skip_analized=1;
                    805:                                                        goto break2;
                    806:                                                case 'q': // eq [lq gq nq]
                    807:                                                        result=c=='e'?SEQ:BAD_STRING_COMPARISON_OPERATOR;
                    808:                                                        skip_analized=1;
                    809:                                                        goto break2;
                    810:                                                }
1.67      paf       811:                                        }
                    812:                                break;
                    813:                        case 'i':
                    814:                                if(end==begin) // right after whitespace
1.117     paf       815:                                        if(isspace(PC.source[1])) {
                    816:                                                switch(PC.source[0]) {
                    817:                                                case 'n': // in
1.95      paf       818:                                                        skip_analized=1;
                    819:                                                        result=IN;
                    820:                                                        goto break2;
1.117     paf       821:                                                case 's': // is
1.95      paf       822:                                                        skip_analized=1;
                    823:                                                        result=IS;
                    824:                                                        goto break2;
                    825:                                                }
1.67      paf       826:                                        }
                    827:                                break;
                    828:                        case 'd':
                    829:                                if(end==begin) // right after whitespace
1.114     paf       830:                                        if(PC.source[0]=='e' && PC.source[1]=='f') { // def
1.67      paf       831:                                                skip_analized=2;
                    832:                                                result=DEF;
1.58      paf       833:                                                goto break2;
1.50      paf       834:                                        }
1.48      paf       835:                                break;
                    836:                        case ' ': case '\t': case '\n':
1.63      paf       837:                                if(end!=begin) { // there were a string after previous operator?
                    838:                                        result=0; // return that string
                    839:                                        goto break2;
1.48      paf       840:                                }
1.63      paf       841:                                // that's a leading|traling space or after-operator-space
                    842:                                // ignoring it
                    843:                                // reset piece 'begin' position & line
1.114     paf       844:                                begin=PC.source; // after whitespace char
                    845:                                begin_line=PC.line;
1.48      paf       846:                                continue;
1.1       paf       847:                        }
                    848:                        break;
                    849: 
1.10      paf       850:                // VARIABLE GET/PUT/WITH
1.1       paf       851:                case LS_VAR_NAME_SIMPLE:
1.69      paf       852:                case LS_EXPRESSION_VAR_NAME:
1.114     paf       853:                        if(PC.ls==LS_EXPRESSION_VAR_NAME) {
1.56      paf       854:                                // name in expr ends also before binary operators 
1.48      paf       855:                                switch(c) {
1.92      paf       856:                                case '-': 
1.48      paf       857:                                        pop_LS(PC);
1.114     paf       858:                                        PC.source--;  if(--PC.col<0) { PC.line--;  PC.col=-1; }
1.48      paf       859:                                        result=EON;
                    860:                                        goto break2;
                    861:                                }
                    862:                        }
                    863:                        switch(c) {
                    864:                        case 0:
                    865:                        case ' ': case '\t': case '\n':
                    866:                        case ';':
1.64      paf       867:                        case ']': case '}': case ')': case '"':
1.83      paf       868:                        case '<': case '>':  // these stand for HTML brackets and expression binary ops
1.92      paf       869:                        case '+': case '*': case '/': case '%': 
                    870:                        case '&': case '|': 
                    871:                        case '=': case '!':
1.99      paf       872:                        // common delimiters
1.101     paf       873:                        case '\'': case ',':
1.1       paf       874:                                pop_LS(PC);
1.114     paf       875:                                PC.source--;  if(--PC.col<0) { PC.line--;  PC.col=-1; }
1.13      paf       876:                                result=EON;
1.1       paf       877:                                goto break2;
1.48      paf       878:                        case '[':
1.114     paf       879:                                PC.ls=LS_VAR_SQUARE;
1.1       paf       880:                                lexical_brackets_nestage=1;
1.48      paf       881:                                RC;
                    882:                        case '{':
                    883:                                if(begin==end) { // ${name}, no need of EON, switching LS
1.114     paf       884:                                        PC.ls=LS_VAR_NAME_CURLY; 
1.48      paf       885:                                } else {
1.114     paf       886:                                        PC.ls=LS_VAR_CURLY;
1.48      paf       887:                                        lexical_brackets_nestage=1;
                    888:                                }
1.69      paf       889: 
1.48      paf       890:                                RC;
                    891:                        case '(':
1.114     paf       892:                                PC.ls=LS_VAR_ROUND;
1.1       paf       893:                                lexical_brackets_nestage=1;
1.48      paf       894:                                RC;
                    895:                        case '.': // name part delim
                    896:                        case '$': // name part subvar
                    897:                        case ':': // ':name' or 'class:name'
                    898:                                RC;
1.1       paf       899:                        }
                    900:                        break;
1.48      paf       901: 
1.1       paf       902:                case LS_VAR_NAME_CURLY:
1.48      paf       903:                        switch(c) {
                    904:                        case '}': // ${name} finished, restoring LS
1.1       paf       905:                                pop_LS(PC);
1.48      paf       906:                                RC;
                    907:                        case '.': // name part delim
                    908:                        case '$': // name part subvar
                    909:                        case ':': // ':name' or 'class:name'
                    910:                                RC;
1.1       paf       911:                        }
                    912:                        break;
1.48      paf       913: 
                    914:                case LS_VAR_SQUARE:
                    915:                        switch(c) {
                    916:                        case '$':
1.10      paf       917:                                push_LS(PC, LS_VAR_NAME_SIMPLE);
1.48      paf       918:                                RC;
                    919:                        case '^':
1.10      paf       920:                                push_LS(PC, LS_METHOD_NAME);
1.48      paf       921:                                RC;
                    922:                        case ']':
1.1       paf       923:                                if(--lexical_brackets_nestage==0) {
                    924:                                        pop_LS(PC);
1.48      paf       925:                                        RC;
1.1       paf       926:                                }
1.48      paf       927:                                break;
                    928:                        case ';': // operator_or_fmt;value delim
                    929:                                RC;
                    930:                        case '[':
                    931:                                lexical_brackets_nestage++;
                    932:                                break;
1.1       paf       933:                        }
                    934:                        break;
1.48      paf       935: 
1.1       paf       936:                case LS_VAR_CURLY:
1.48      paf       937:                        switch(c) {
                    938:                        case '$':
1.10      paf       939:                                push_LS(PC, LS_VAR_NAME_SIMPLE);
1.48      paf       940:                                RC;
                    941:                        case '^':
1.10      paf       942:                                push_LS(PC, LS_METHOD_NAME);
1.48      paf       943:                                RC;
                    944:                        case '}':
1.1       paf       945:                                if(--lexical_brackets_nestage==0) {
                    946:                                        pop_LS(PC);
1.48      paf       947:                                        RC;
1.1       paf       948:                                }
1.48      paf       949:                                break;
                    950:                        case '{':
1.1       paf       951:                                lexical_brackets_nestage++;
1.48      paf       952:                                break;
                    953:                        }
1.1       paf       954:                        break;
                    955: 
1.10      paf       956:                // METHOD CALL
1.1       paf       957:                case LS_METHOD_NAME:
1.48      paf       958:                        switch(c) {
                    959:                        case '[':
1.114     paf       960:                                PC.ls=LS_METHOD_SQUARE;
1.1       paf       961:                                lexical_brackets_nestage=1;
1.48      paf       962:                                RC;
                    963:                        case '{':
1.114     paf       964:                                PC.ls=LS_METHOD_CURLY;
1.1       paf       965:                                lexical_brackets_nestage=1;
1.48      paf       966:                                RC;
1.69      paf       967:                        case '(':
1.114     paf       968:                                PC.ls=LS_METHOD_ROUND;
1.69      paf       969:                                lexical_brackets_nestage=1;
                    970:                                RC;
1.48      paf       971:                        case '.': // name part delim 
                    972:                        case '$': // name part subvar
                    973:                        case ':': // ':name' or 'class:name'
                    974:                                RC;
1.1       paf       975:                        }
                    976:                        break;
1.48      paf       977: 
                    978:                case LS_METHOD_SQUARE:
                    979:                        switch(c) {
                    980:                        case '$':
1.10      paf       981:                                push_LS(PC, LS_VAR_NAME_SIMPLE);
1.48      paf       982:                                RC;
                    983:                        case '^':
1.10      paf       984:                                push_LS(PC, LS_METHOD_NAME);
1.48      paf       985:                                RC;
                    986:                        case ';': // param delim
                    987:                                RC;
                    988:                        case ']':
1.1       paf       989:                                if(--lexical_brackets_nestage==0) {
1.114     paf       990:                                        PC.ls=LS_METHOD_AFTER;
1.48      paf       991:                                        RC;
1.1       paf       992:                                }
1.48      paf       993:                                break;
                    994:                        case '[':
1.1       paf       995:                                lexical_brackets_nestage++;
1.48      paf       996:                                break;
                    997:                        }
1.1       paf       998:                        break;
1.48      paf       999: 
1.1       paf      1000:                case LS_METHOD_CURLY:
1.48      paf      1001:                        switch(c) {
                   1002:                        case '$':
1.10      paf      1003:                                push_LS(PC, LS_VAR_NAME_SIMPLE);
1.48      paf      1004:                                RC;
                   1005:                        case '^':
1.10      paf      1006:                                push_LS(PC, LS_METHOD_NAME);
1.94      paf      1007:                                RC;
                   1008:                        case ';': // param delim
1.48      paf      1009:                                RC;
                   1010:                        case '}':
1.1       paf      1011:                                if(--lexical_brackets_nestage==0) {
1.114     paf      1012:                                        PC.ls=LS_METHOD_AFTER;
1.48      paf      1013:                                        RC;
1.1       paf      1014:                                }
1.48      paf      1015:                                break;
                   1016:                        case '{':
1.1       paf      1017:                                lexical_brackets_nestage++;
1.48      paf      1018:                                break;
                   1019:                        }
1.1       paf      1020:                        break;
1.48      paf      1021: 
1.1       paf      1022:                case LS_METHOD_AFTER:
1.69      paf      1023:                        if(c=='[') {/* ][ }[ )[ */
1.114     paf      1024:                                PC.ls=LS_METHOD_SQUARE;
1.1       paf      1025:                                lexical_brackets_nestage=1;
1.48      paf      1026:                                RC;
1.1       paf      1027:                        }                                          
1.69      paf      1028:                        if(c=='{') {/* ]{ }{ ){ */
1.114     paf      1029:                                PC.ls=LS_METHOD_CURLY;
1.69      paf      1030:                                lexical_brackets_nestage=1;
                   1031:                                RC;
                   1032:                        }                                          
                   1033:                        if(c=='(') {/* ]( }( )( */
1.114     paf      1034:                                PC.ls=LS_METHOD_ROUND;
1.1       paf      1035:                                lexical_brackets_nestage=1;
1.48      paf      1036:                                RC;
1.1       paf      1037:                        }                                          
                   1038:                        pop_LS(PC);
1.114     paf      1039:                        PC.source--;  if(--PC.col<0) { PC.line--;  PC.col=-1; }
1.13      paf      1040:                        result=EON;
1.1       paf      1041:                        goto break2;
                   1042:                }
1.9       paf      1043:                if(c==0) {
1.1       paf      1044:                        result=-1;
                   1045:                        break;
                   1046:                }
                   1047:        }
                   1048: 
                   1049: break2:
1.59      paf      1050:        if(end!=begin) { // there is last piece?
                   1051:                if((c=='@' || c==0) && end[-1]=='\n') { // we are before LS_DEF_NAME or EOF?
                   1052:                        // strip last \n
1.10      paf      1053:                        end--;
1.59      paf      1054:                }
                   1055:                if(end!=begin) { // last piece still alive?
                   1056:                        // append it
1.121     paf      1057:                        PC.string->APPEND_CLEAN(begin, end-begin, PC.file, begin_line/*, start_col*/);
1.30      paf      1058:                }
1.59      paf      1059:        }
1.114     paf      1060:        if(PC.string->size()) { // something accumulated?
1.17      paf      1061:                // create STRING value: array of OP_VALUE+vstring
1.114     paf      1062:                *lvalp=VL(NEW VString(*PC.string));
1.10      paf      1063:                // new pieces storage
1.114     paf      1064:                PC.string=NEW String(POOL);
1.58      paf      1065:                // make current result be pending for next call, return STRING for now
1.114     paf      1066:                PC.pending_state=result;  result=STRING;
1.58      paf      1067:        }
1.67      paf      1068:        if(skip_analized) {
1.114     paf      1069:                PC.source+=skip_analized;  PC.col+=skip_analized;
1.1       paf      1070:        }
1.58      paf      1071:        return result;
1.1       paf      1072: }
                   1073: 
1.110     paf      1074: static int real_yyerror(parse_control *pc, char *s) {  // Called by yyparse on error
1.114     paf      1075:           strncpy(PC.error, s, MAX_STRING);
1.1       paf      1076:           return 1;
1.110     paf      1077: }
1.1       paf      1078: 
1.110     paf      1079: static void yyprint(FILE *file, int type, YYSTYPE value) {
                   1080:        if(type==STRING)
1.120     paf      1081:                fprintf(file, " \"%s\"", LA2S(value)->cstr());
1.110     paf      1082: }

E-mail: