由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - lex/yacc如何reset buffer?
相关主题
谁知道如何调试yacc程序?A C++ exception question
多次调用yyarse()的buffer flush问题。编程题一道
请教一个parser的问题C# binary file reading problem
does the system guarantee this? (转载)A question related to pipe
rust现在很火Python里边file writer的问题
请问如何恢复正常的IO?一道编程题 - throw Exceptions
发现自己写buffer还是能加速fwrite的How to Parsing function in haskell?
大家帮我看看C文件输入函数fprintf的问题parsing bibliography and sorting (转载)
相关话题的讨论汇总
话题: buffer话题: yylex话题: yyerror话题: reset话题: yacc
进入Programming版参与讨论
1 (共1页)
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

1 (共1页)
进入Programming版参与讨论
相关主题
parsing bibliography and sorting (转载)rust现在很火
问java api的问题请问如何恢复正常的IO?
parsing file in node: js or python ?发现自己写buffer还是能加速fwrite的
multi-thread 一问,大家帮我看看C文件输入函数fprintf的问题
谁知道如何调试yacc程序?A C++ exception question
多次调用yyarse()的buffer flush问题。编程题一道
请教一个parser的问题C# binary file reading problem
does the system guarantee this? (转载)A question related to pipe
相关话题的讨论汇总
话题: buffer话题: yylex话题: yyerror话题: reset话题: yacc