--- parser3/src/main/compile.y 2001/03/14 08:50:03 1.98 +++ parser3/src/main/compile.y 2001/03/20 17:52:39 1.106.2.1 @@ -1,20 +1,22 @@ -/* - Parser +/** @file + Parser: compiler(lexical parser and grammar). + Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) + Author: Alexander Petrosyan (http://design.ru/paf) - $Id: compile.y,v 1.98 2001/03/14 08:50:03 paf Exp $ + $Id: compile.y,v 1.106.2.1 2001/03/20 17:52:39 paf Exp $ */ -/* - TODO.parser4: - cache compiled code from request to request. to do that... - 1: make method definitions, @CLASS, @BASE, @USE instructions, +/** + @todo parser4: + - cache compiled code from request to request. to do that... + -#: make method definitions, @CLASS, @BASE, @USE instructions, which would be executed afterwards, and actions now performed at compile time would be delayed to run time. - 2: make cache expiration on time and on disk-change of class source - 3: in apache use subpools for compiled class storage - 4: in iis make up specialized Pool object for that + -#: make cache expiration on time and on disk-change of class source + -#: in apache use subpools for compiled class storage + -#: in iis make up specialized Pool object for that */ %{ @@ -22,7 +24,7 @@ #define YYPARSE_PARAM pc #define YYLEX_PARAM pc #define YYDEBUG 1 -#define YYERROR_VERBOSE +#define YYERROR_VERBOSE 1 #define yyerror(msg) real_yyerror((parse_control *)pc, msg) #define YYPRINT(file, type, value) yyprint(file, type, value) @@ -50,6 +52,7 @@ int yylex(YYSTYPE *lvalp, void *pc); #define POOL *PC->pool #undef NEW #define NEW new(POOL) +#ifndef DOXYGEN %} %pure_parser @@ -130,7 +133,7 @@ control_method: '@' STRING '\n' YYERROR; } if(command==CLASS_NAME) { - if(PC->cclass!=&PC->request->root_class) { // already changed from default? + if(PC->cclass!=&PC->request->ROOT) { // already changed from default? strcpy(PC->error, "class already have a name '"); strncat(PC->error, PC->cclass->name().cstr(), 100); strcat(PC->error, "'"); @@ -143,7 +146,7 @@ control_method: '@' STRING '\n' PC->cclass=NEW VClass(POOL); PC->cclass->set_name(*name); // defaulting base. may change with @BASE - PC->cclass->set_base(PC->request->root_class); + PC->cclass->set_base(PC->request->ROOT); // append to request's classes PC->request->classes().put(*name, PC->cclass); } else { @@ -158,7 +161,7 @@ control_method: '@' STRING '\n' PC->request->use_file(file.cstr()); } } else if(command==BASE_NAME) { - if(PC->cclass->base()!=&PC->request->root_class) { // already changed from default? + if(PC->cclass->base()!=&PC->request->ROOT) { // already changed from default? strcpy(PC->error, "class already have a base '"); strncat(PC->error, PC->cclass->base()->name().cstr(), 100); strcat(PC->error, "'"); @@ -239,7 +242,7 @@ action: get | put | with | call; get: get_value { $$=$1; /* stack: resulting value */ - O($$, OP_WRITE); /* value=pop; wcontext.write(value) */ + O($$, OP_WRITE_VALUE); /* value=pop; wcontext.write(value) */ }; get_value: '$' get_name_value { $$=$2 } get_name_value: name_without_curly_rdive EON | name_in_curly_rdive; @@ -332,7 +335,7 @@ codes__excluding_sole_str_literal: actio call: call_value { $$=$1; /* stack: value */ - O($$, OP_WRITE); /* value=pop; wcontext.write(value) */ + O($$, OP_WRITE_VALUE); /* value=pop; wcontext.write(value) */ }; call_value: '^' call_name store_params EON { /* ^field.$method{vasya} */ $$=$2; /* with_xxx,diving code; stack: context,method_junction */ @@ -377,7 +380,7 @@ store_code_param_part: ; store_expr_param_part: write_expr_value { $$=N(POOL); - PCA($$, $1); + PEA($$, $1); }; store_curly_param_part: maybe_codes { $$=N(POOL); @@ -385,7 +388,7 @@ store_curly_param_part: maybe_codes { }; write_expr_value: expr_value { $$=$1; - O($$, OP_WRITE); + O($$, OP_WRITE_EXPR_RESULT); }; /* name */ @@ -419,7 +422,7 @@ name_expr_with_subvar_value: STRING subv $$=N(POOL); O($$, OP_CREATE_EWPOOL); P($$, $1); - O($$, OP_WRITE); + O($$, OP_WRITE_VALUE); P($$, $2); O($$, OP_REDUCE_EWPOOL); }; @@ -453,7 +456,7 @@ with: '$' name_without_curly_rdive '{' c O($$, OP_CREATE_RWPOOL); P($$, $4); O($$, OP_REDUCE_RWPOOL); - O($$, OP_WRITE); + O($$, OP_WRITE_VALUE); }; /* expr */ @@ -512,7 +515,7 @@ string_inside_quotes_value: maybe_codes /* basics */ write_string: STRING { - // optimized from OP_STRING+OP_WRITE to OP_STRING__WRITE + // optimized from OP_STRING+OP_WRITE_VALUE to OP_STRING__WRITE change_string_literal_to_write_string_literal($$=$1) }; @@ -520,6 +523,7 @@ empty_string_value: /* empty */ { $$=VL( empty: /* empty */ { $$=N(POOL) }; %% +#endif /* 000$111(2222)00 @@ -808,6 +812,8 @@ int yylex(YYSTYPE *lvalp, void *pc) { case '+': case '*': case '/': case '%': case '&': case '|': case '=': case '!': + // common delimiters + case '\'': case ',': pop_LS(PC); PC->source--; if(--PC->col<0) { PC->line--; PC->col=-1; } result=EON; @@ -1010,8 +1016,6 @@ break2: int real_yyerror(parse_control *pc, char *s) /* Called by yyparse on error */ { - //fprintf(stderr, "[%s]\n", s); - strncpy(pc->error, s, MAX_STRING); // TODO: перепроверить с треклятым последним байтом return 1; }