使用JavaCC解析C语法的源码
作为项目作业,我需要从 Java 解析纯 C 语法以生成 AST 输出。 的语法文件中找到的文件 c.jj:
作为一个初创公司,我使用的是我在http: //java.net/projects/javacc/sources/svn/
但我发现它只有句法和词汇动作,没有解析 C 源代码的真正语义。是否有其他一些包含 typedef、变量、构造函数、包含文件的源?
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/
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你可以去寻找完整的语法。这样你会学到很多东西吗?
你可以问你的讲师哪一个会给他们留下更深刻的印象:通过编写自己的规则来实现 C 语法的一些小子集,还是通过在 google 上搜索替代的完整规则?
我相信编写您自己的规则 - 甚至您自己手工制作的解析器 - 将是一个更有用的练习。即使它只是解析表达式。
You could go looking for a complete grammar. Will you learn much this way?
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.