It is a function of your grammar, which is badly organized and ambiguous. This is causing the generation of huge DFA tables and convoluted code.
You will find that it is the same with Java if you set the –X settings to the same as C, however the DFA tables in Java are generated as run length compressed strings, which means that when you look at the source code it fools you in to thinking that it is smaller but it is just replaced by a huge overhead in expanding the strings at runtime instead. The C code is generated with static initialized tables, which means that there is no runtime overhead. However, the C target also favors the generation of switch statements when it can, and when your grammar is not so great, then you reap the consequences in code gen. ANTLR4 will be more forgiving in the way you organize the grammar, but you still have to think about it. Follow the advice about removing backtracking one rule at a time, do the left factoring, and you will find it is good. When you are writing a grammar, you should do so in small increments, solving any introduced ambiguities as you go, and not piling them up until the end as then it will seem like an intractable problem. Jim *From:* Mike Lischke [mailto:[email protected]] *Sent:* Wednesday, April 04, 2012 8:27 AM *To:* Jim Idle *Cc:* ANTLR Mailing List *Subject:* Re: [antlr-dev] C and C++ targets in ANTLR Hey Jim, Without the grammar, or a stack trace or some indication of whether you mean that the 3.4 tool crashes when generating C, there is nothing I can do to help you here. After several hours work I found the problem in the grammar and solved it. It was the "handler" rule in line 2740 (the two alternatives ending with limit?). Now that I could create the parser file I'm actually surprised about its size. This is the biggest source file I have ever seen (31MB, 800K LOC). It effectively doubles the size of our code base. And it takes 16 mins to compile. Since you seem to be the author of the C target, do you have any advice to get this to a smaller size? 800K in a single file is simply crazy. Mike -- www.soft-gems.net
_______________________________________________ antlr-dev mailing list [email protected] http://www.antlr.org/mailman/listinfo/antlr-dev
