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

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

E-mail: