使用JavaCC解析C语法的源代码 [英] Source for parsing C grammar using JavaCC

查看:239
本文介绍了使用JavaCC解析C语法的源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


作为项目任务,我需要从Java解析纯C语法以生成AST输出.作为启动,我使用的是在


As an project assignment, I need to parse a plain-C grammar from Java to generate AST output. As a startup, I am using the file c.jj that I have found among grammar files at

http://java.net/projects/javacc/sources/svn/

但是我发现它仅具有语法和词法作用,而没有真正的语义来解析C源代码.还有其他一些来源,其中包含typedef,变量,构造函数,包含文件吗?

but I found that it only has syntactic and lexical actions and no real semantics for parsing C source. Is there some other source that incorporate typedef, variables, construct functions, include files?

推荐答案

您可以去寻找完整的语法.这样会学到很多吗?

You could go looking for a complete grammar. Will you learn much this way?

您可能会问您的讲师,哪个会给他们留下更深刻的印象:通过编写自己的规则或通过在Google上搜索替代完整规则来实现C语法的一小部分?

You could ask your lecturer which would impress them more: implementing some small subset of C grammar by writing your own rules, or by searching google for alternative complete rules?

我相信编写您自己的规则-甚至您自己创建的解析器-都会是一个更有用的练习.即使只解析表达式.

I trust writing your own rules - and even your own hand-crafted parser - will be more a more useful exercise. Even if its only parsing expressions.

这篇关于使用JavaCC解析C语法的源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆