[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Metal tree misconstruction (was: Bug in Yacc or Metal ?)
In order to keep you waiting, here is a (dirty) way to have METAL build
the trees you want. Just include some lines in your LANG.tokens file to
have your lexLANG.l file look like:
%{
...
char yyprevtext[YYLMAX], *yytmptext; int yy_n;
yylex2(yyn) int yyn; {yy_n=yyn;strcpy(yyprevtext,yytext);return(yylex());}
...
%}
...
%%
...
%%
...
#define yylex() yylex2(yy_n)
#define action(N) \
fprintf(yaccout,"%d\n",N); \
yytmptext = (yy_n == -2) ? yyprevtext : yytext ; yy_n = 0; }; \
{char *yytext = yytmptext
...
In your case, this would look like:
1i\
%{\
char yyprevtext[YYLMAX], *yytmptext; int yy_n;\
yylex2(yyn) int yyn; {yy_n = yyn;strcpy(yyprevtext,yytext);return(yylex());}\
%}\
%S entrypoint\
%%\
\\n fprintf(yaccout,"-2\\n");\
[ \\t] ;
$a\
[0-9]+ return(INT);\
\\"[a-zA-Z0-9_]*\\" return(STR);\
[a-zA-Z][a-zA-Z0-9_]* return(ID);\
%%\
#define yylex() yylex2(yy_n)\
#define action(N) \\\
fprintf(yaccout,"%d\\\n",N); \\\
yytmptext = (yy_n == -2) ? yyprevtext : yytext ; yy_n = 0; }; \\\
{char *yytext = yytmptext