--- parser3/src/main/compile.y 2001/02/21 06:21:19 1.3 +++ parser3/src/main/compile.y 2001/02/21 07:34:03 1.7 @@ -4,27 +4,27 @@ #define YYLEX_PARAM pc #define YYDEBUG 1 #define YYERROR_VERBOSE +#define yyerror(msg) real_yyerror((parse_control *)pc, msg) #define YYPRINT(file, type, value) yyprint (file, type, value) #include #include #include -#include "pa_exception.h" #include "compile_tools.h" -int yyerror (char *s); +int real_yyerror (parse_control *pc, char *s); static void yyprint (FILE *file, int type, YYSTYPE value); int yylex(YYSTYPE *lvalp, void *pc); -#define PC ((struct parse_control *)pc) +#define PC ((parse_control *)pc) %} %pure_parser -%token BREAK -%token STR_LITERAL +%token END_OF_NAME +%token STRING %token BOGUS %% @@ -48,7 +48,7 @@ get: '$' any_name { OP($$,OP_WRITE); /* value=pop; write(value) */ }; -any_name: name_without_curly_rdive BREAK | name_in_curly_rdive; +any_name: name_without_curly_rdive END_OF_NAME | name_in_curly_rdive; name_in_curly_rdive: '{' name_without_curly_rdive '}' { $$=$2 }; name_without_curly_rdive: name_rdive { @@ -86,7 +86,7 @@ constructor_value: ; constructor_one_param_value: empty_value /* optimized $var() case */ -| STR_LITERAL /* optimized $var(STR_LITERAL) case */ +| STRING /* optimized $var(STRING) case */ | complex_constructor_param_value /* $var(something complex) */ ; empty_value: empty; @@ -100,9 +100,8 @@ complex_constructor_param_body: codes__excluding_sole_str_literal | codes__str__followed_by__excluding_sole_str_literal ; -constructor_two_params_value: STR_LITERAL ';' constructor_one_param_value { - const String *operator_or_fmtS=LA2S($1); - char *operator_or_fmt=operator_or_fmtS->cstr(); +constructor_two_params_value: STRING ';' constructor_one_param_value { + char *operator_or_fmt=LA2S($1)->cstr(); $$=N(PC->pool); P($$, $1);/* stack: ncontext name operator_or_fmt */ P($$, $3); /* stack: ncontext name operator_or_fmt expr */ @@ -114,9 +113,8 @@ constructor_two_params_value: STR_LITERA OP($$, OP_MODIFY_EVAL); break; default: - PC->pool->exception().raise(0,0, - operator_or_fmtS, - "invalid modification operator"); + strcpy(PC->error, "invalid modification operator"); + YYERROR; } /* stack: ncontext name value */ }; @@ -124,7 +122,7 @@ constructor_two_params_value: STR_LITERA /* call */ -call: '^' name_expr_dive store_params BREAK { /* ^field.$method{vasya} */ +call: '^' name_expr_dive store_params END_OF_NAME { /* ^field.$method{vasya} */ /* TODO: подсмотреть в $3, и если там в первом элементе первая буква ":" то выкинуть её и делать не OP_WITH_READ, а WITH_ROOT @@ -180,10 +178,10 @@ name_advance2: name_expr_value { $$=$1; /* stack: context,name */ OP($$,OP_GET_ELEMENT); /* name=pop; context=pop; stack: context.get_element(name) */ } -| STR_LITERAL BOGUS +| STRING BOGUS ; name_expr_value: - STR_LITERAL /* subname_is_const */ + STRING /* subname_is_const */ | name_expr_subvar_value /* $subname_is_var_value */ | name_expr_with_subvar_value /* xxx$part_of_subname_is_var_value[$...] */ ; @@ -191,7 +189,7 @@ name_expr_subvar_value: '$' subvar_ref_n $$=$2; OP($$,OP_GET_ELEMENT); }; -name_expr_with_subvar_value: STR_LITERAL subvar_get_writes { +name_expr_with_subvar_value: STRING subvar_get_writes { $$=N(PC->pool); OP($$, OP_CREATE_EWPOOL); P($$,$1); @@ -199,7 +197,7 @@ name_expr_with_subvar_value: STR_LITERAL P($$,$2); OP($$,OP_REDUCE_EWPOOL); }; -subvar_ref_name_rdive: STR_LITERAL { +subvar_ref_name_rdive: STRING { /* TODO: подсмотреть в $1, и если там в первом элементе первая буква ":" то выкинуть её и делать не OP_WITH_READ, а WITH_ROOT @@ -239,7 +237,7 @@ codes__excluding_sole_str_literal: P($$,$2); } ; -write_str_literal: STR_LITERAL { +write_str_literal: STRING { $$=$1; OP($$,OP_WRITE); }; @@ -285,8 +283,11 @@ int yylex(YYSTYPE *lvalp, void *pc) { while(1) { c=*PC->source++; - if(c=='\n') + if(c=='\n') { PC->line++; + PC->col=1; + } + PC->col++; /* escaping: ^^ ^$ ^; ^) ^} ^( ^{ */ if(c=='^') { @@ -326,11 +327,11 @@ int yylex(YYSTYPE *lvalp, void *pc) { c==' '|| c=='\t' || c=='\n' || c==')' || c=='}') { pop_LS(PC); - PC->source--; - result=BREAK; + PC->source--; PC->col--; + result=END_OF_NAME; goto break2; } - if(PC->source==start && c=='{') { /* ${name}, no need of BREAK, switching LS */ + if(PC->source==start && c=='{') { /* ${name}, no need of END_OF_NAME, switching LS */ PC->ls=LS_VAR_NAME_CURLY; result=c; goto break2; @@ -486,12 +487,13 @@ int yylex(YYSTYPE *lvalp, void *pc) { goto break2; } pop_LS(PC); - PC->source--; - result=BREAK; + PC->source--; PC->col--; + result=END_OF_NAME; goto break2; } if (c == 0) { result=-1; + PC->source--; PC->col--; break; } } @@ -502,19 +504,21 @@ break2: else { PC->pending_state=result; /* append last piece */ - PC->string->APPEND(start, PC->source-start-1, PC->file, start_line); - /* create STR_LITERAL value: array of OP_STRING+string */ + PC->string->APPEND(start, PC->source-start-1, PC->file, start_line/*, start_col*/); + /* create STRING value: array of OP_STRING+string */ *lvalp=L(PC->string); /* new pieces storage */ PC->string=new(*PC->pool) String(*PC->pool); /* go */ - return STR_LITERAL; + return STRING; } } -int yyerror (char *s) /* Called by yyparse on error */ +int real_yyerror (parse_control *pc, char *s) /* Called by yyparse on error */ { - printf ("[%s]\n", s); + fprintf (stderr, "[%s]\n", s); + + s[MAX_STRING-1]=0; strcpy(pc->error, s); return 1; } @@ -524,7 +528,7 @@ static void int type, YYSTYPE value) { - if (type == STR_LITERAL) + if (type == STRING) fprintf (file, " \"%s\"", LA2S(value)->cstr()); }