blizzard213 发表于 2008-07-30 22:53

lemon的几个问题

这几天看lemon 遇到几个问题。
我的开发环境是vs2005 自己编译的lemon1.0

问题1.
我在.y里定义了一个%token_destructor
函数为void token_destructor(Token t)
生成的解析器实现文件里:
static void yy_reduce(
yyParser *yypParser,         /* The parser */
int yyruleno               /* Number of the rule by which to reduce */
)
调用
static void yy_destructor(
yyParser *yypParser,    /* The parser */
YYCODETYPE yymajor,   /* Type code for object to destroy */
YYMINORTYPE *yypminor   /* The object to be destroyed */
)
可是调用时总是不传第一个参数,因此我每次都必须手动添加
不知道这个是为什么?

问题2.
对token_destructor的调用方式:
lemon的文档里的描述是:
在结束reduce时Parse()函数的第三个参数token将会被析构
比如:
Parse(pParser, NUM, t0);
Parse(pParser, PLUS, t0);
Parse(pParser, NUM, t1);
Parse(pParser, 0, t1);
则应该是t1被析构
可实际上我的程序里被析构的是t0
根据我观察实际上是Parse 运算符时传入的token会被析构
当使用NEWLINE方式
Parse(pParser, NUM, t0);
Parse(pParser, PLUS, t0);
Parse(pParser, NUM, t1);
Parse(pParser, NEWLINE, t1);
指定欲析构的token时没错 和文档上说的一样
但是Parse(pParser, PLUS, t0);所指定的t0仍然会被析构
请问这是怎么了?

fineamy 发表于 2008-07-31 09:18

还不知道lemon是什么,回答不了,支持下

The Lemon Parser Generator
Lemon is an LALR(1) parser generator for C or C++. It does the same job as ``bison'' and ``yacc''. But lemon is not another bison or yacc clone. It uses a different grammar syntax which is designed to reduce the number of coding errors. Lemon also uses a more sophisticated parsing engine that is faster than yacc and bison and which is both reentrant and thread-safe. Furthermore, Lemon implements features that can be used to eliminate resource leaks, making is suitable for use in long-running programs such as graphical user interfaces or embedded controllers.

cjaizss 发表于 2008-07-31 10:27

为什么使用lemon(以前从未见过)而不用yacc?

mz198424 发表于 2008-07-31 10:47

回复 #1 blizzard213 的帖子

不懂///:em14:

prolj 发表于 2008-07-31 13:51

回复 #3 cjaizss 的帖子

因为浙大出版社出了一本书 lemon源代码分析

blizzard213 发表于 2008-07-31 22:28

原帖由 mz198424 于 2008-7-31 10:47 发表 http://linux.chinaunix.net/bbs/images/common/back.gif
不懂///:em14:

lemon比较简单吧 一共就4千行代码
sqlite3的sql前端也是用lemon构造的
我是初学者,想自己编译lemon然后应用然后再深入学习lemon的构造原理 也许这样学得深刻一些

我还是去找浙大那本书看看吧
页: [1]
查看完整版本: lemon的几个问题