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

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

E-mail: