[antlr-interest] Problem with splitting grammars

Mu Qiao qiaomuf at gmail.com
Mon Jul 4 02:17:36 PDT 2011


I have one big grammar that needs to be split to reduce compile time(C
source). For ANTLR 3.1.3 there are two problems:
1. The generated source code may change every time I run ANTLR even if
I don't change the grammar
http://paste.pocoo.org/show/428505/ shows the difference.

2. The comment probably shouldn't tell about the date
I use sed to remove the comment but I don't think it's a good idea.
ANTLR shouldn't generate different source code if I don't change the
grammar. The date information should belong to the property of the
generated files, not the content of these files.

Then I tried ANTLR 3.3 and I got the following error when generating
the source code:
error(10):  internal error: bashast/libbashWalker.g :
java.lang.NullPointerException
org.antlr.codegen.Target.getTokenTypeAsTargetLabel(Target.java:145)
org.antlr.codegen.CodeGenerator.getTokenTypeAsTargetLabel(CodeGenerator.java:858)
org.antlr.codegen.ACyclicDFACodeGenerator.walkFixedDFAGeneratingStateMachine(ACyclicDFACodeGenerator.java:119)
org.antlr.codegen.ACyclicDFACodeGenerator.genFixedLookaheadDecision(ACyclicDFACodeGenerator.java:47)
org.antlr.codegen.CodeGenerator.genLookaheadDecision(CodeGenerator.java:646)
org.antlr.grammar.v2.CodeGenTreeWalker.block(CodeGenTreeWalker.java:1018)
org.antlr.grammar.v2.CodeGenTreeWalker.ebnf(CodeGenTreeWalker.java:1871)
org.antlr.grammar.v2.CodeGenTreeWalker.element(CodeGenTreeWalker.java:1704)
org.antlr.grammar.v2.CodeGenTreeWalker.tree(CodeGenTreeWalker.java:2277)
org.antlr.grammar.v2.CodeGenTreeWalker.element(CodeGenTreeWalker.java:1633)
org.antlr.grammar.v2.CodeGenTreeWalker.alternative(CodeGenTreeWalker.java:1306)
org.antlr.grammar.v2.CodeGenTreeWalker.block(CodeGenTreeWalker.java:1081)
org.antlr.grammar.v2.CodeGenTreeWalker.rule(CodeGenTreeWalker.java:797)
org.antlr.grammar.v2.CodeGenTreeWalker.rules(CodeGenTreeWalker.java:588)
org.antlr.grammar.v2.CodeGenTreeWalker.grammarSpec(CodeGenTreeWalker.java:530)
org.antlr.grammar.v2.CodeGenTreeWalker.grammar(CodeGenTreeWalker.java:336)
org.antlr.codegen.CodeGenerator.genRecognizer(CodeGenerator.java:430)
org.antlr.Tool.generateRecognizer(Tool.java:642)
org.antlr.Tool.process(Tool.java:455)
org.antlr.Tool.main(Tool.java:89)

Here are my grammars:
https://github.com/qiaomuf/libbash/blob/42193d91c43d12bcc3113336e5e73e74ca679c82/bashast/libbashWalker.g
https://github.com/qiaomuf/libbash/blob/42193d91c43d12bcc3113336e5e73e74ca679c82/bashast/libbashPattern.g

-- 
Best wishes,
Mu Qiao
GnuPG fingerprint: 92B1 B0C4 8D14 F8C4 EFA5  3ACC 30B3 0DE4 17B1 57E9


More information about the antlr-interest mailing list