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

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

E-mail: