g*********s 发帖数: 1782 | 1 有这么一个问题:
for (int i = 0; i < n; i ++) {
yyin = fopen(f[i], "r");
try {
yyparse();
}
catch ...
}
这里.y里重定义了yyerror,有语法错就throw一个exception。
现在的问题是,如果f[1]有parse error,之后的f[2],f[3]等还是从f[1]原来的yylex
buffer里拿token,而不是自己的文件里。
怎么才能在yyerror()里,throw exception之前reset yylex buffer呢?放狗搜了一下
,有个YY_FLUSH_BUFFER的macro,但这个是只在.l里可见的,而.y里不可见。
另外现在还有人用flex/bison吗?很麻烦啊。 |
O*******d 发帖数: 20343 | 2 Used 10 years ago. Forget most of it. |
p***o 发帖数: 1252 | 3 And you always find the version you have cannot compile
the files others wrote ;)
【在 O*******d 的大作中提到】 : Used 10 years ago. Forget most of it.
|
l**b 发帖数: 457 | 4 去年还在用lex\yacc,感觉有点老了,你的问题我无解,不过你如果真的很不爽,可以
看看其他replacement,我后来就改用antlr了,我记忆里面应该也可以生成c/c++的
code,而且有个eclipse的plugin,挺不错的。大牛们不要鄙视我。 |
t****t 发帖数: 6806 | 5 you can write a helper function with yy_flush_buffer at the end of .l file.
.y file will include a prototype of it and call it.
the general rule is put all lexical operation into .l file, and all syntax o
peration into .y file. they may call each other.
flex/bison is ok, not easy to use, but as a fast parser prototype tool, it i
s ok. you can add/change syntax easily.
yylex
【在 g*********s 的大作中提到】 : 有这么一个问题: : for (int i = 0; i < n; i ++) { : yyin = fopen(f[i], "r"); : try { : yyparse(); : } : catch ... : } : 这里.y里重定义了yyerror,有语法错就throw一个exception。 : 现在的问题是,如果f[1]有parse error,之后的f[2],f[3]等还是从f[1]原来的yylex
|