免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 5116 | 回复: 5
打印 上一主题 下一主题

lemon的几个问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-07-30 22:53 |只看该作者 |倒序浏览
5可用积分
这几天看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仍然会被析构
请问这是怎么了?

论坛徽章:
0
2 [报告]
发表于 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.

论坛徽章:
3
2015年迎新春徽章
日期:2015-03-04 09:56:11数据库技术版块每日发帖之星
日期:2016-08-03 06:20:00数据库技术版块每日发帖之星
日期:2016-08-04 06:20:00
3 [报告]
发表于 2008-07-31 10:27 |只看该作者
为什么使用lemon(以前从未见过)而不用yacc?

论坛徽章:
52
码神
日期:2017-03-28 10:27:10综合交流区版块每日发帖之星
日期:2015-10-11 06:20:00综合交流区版块每日发帖之星
日期:2015-09-28 06:20:00综合交流区版块每日发帖之星
日期:2015-09-22 06:20:00每日论坛发贴之星
日期:2015-09-12 06:20:00综合交流区版块每日发帖之星
日期:2015-09-12 06:20:00综合交流区版块每日发帖之星
日期:2015-09-08 06:20:00综合交流区版块每日发帖之星
日期:2015-09-05 06:20:00综合交流区版块每日发帖之星
日期:2015-09-04 06:20:002015亚冠之德黑兰石油
日期:2015-09-01 10:41:53每日论坛发贴之星
日期:2015-10-11 06:20:00综合交流区版块每日发帖之星
日期:2015-10-12 06:20:00
4 [报告]
发表于 2008-07-31 10:47 |只看该作者

回复 #1 blizzard213 的帖子

不懂///

论坛徽章:
0
5 [报告]
发表于 2008-07-31 13:51 |只看该作者

回复 #3 cjaizss 的帖子

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

论坛徽章:
0
6 [报告]
发表于 2008-07-31 22:28 |只看该作者
原帖由 mz198424 于 2008-7-31 10:47 发表
不懂///


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

我还是去找浙大那本书看看吧
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP