Katy
Katy

Reputation: 39

C grammar for ANTLR v4

I was wondering if anyone had a working C grammar for ANTLRv4 besides the one on Github?

I can't get the existing one to work at all, it won't even parse the sample files. It may be i'm missing something but I haven't had a problem with any of the other grammars.

I was thinking about modifying the existing one/writing my own, but I don't really have the time - I have limited time to work on this project.

Any help much appreciated.

thanks,

Katy

Upvotes: 2

Views: 2807

Answers (2)

Alistar Klay
Alistar Klay

Reputation: 1

you can test rule translationunit instead of test rule primaryexpression

Upvotes: 0

alinsoar
alinsoar

Reputation: 15803

So you cannot create a working C grammar in less than a few months and it is more complex than it seems like. My opinion is that parsing all C (without preprocessor) takes 6 months to do it well.

For example, the first impression is that C grammar is context-free, but in reality it is context-sensitive.

Take the official grammar from Appendix A of the ISO Standard and start implementing sublanguages from it, inserting nonterminals one by one.

Upvotes: 3

Related Questions