-->

Source for parsing C grammar using JavaCC

2019-09-19 10:53发布

问题:


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?

回答1:

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.