Posts

Showing posts from July, 2009

Antlr3 Code Too Big

Antlr3 can generate very large java files for complex grammars. Javac can have a problem compiling them due to the size limit of static initializers in a class file. An error like the following : code too large > > [12:56:12] public static final String[] tokenNames = new String[] { > > [12:56:12] ^ > > [12:56:12] 1 error My solution was to post process the generated Java files. Moving a large section of static final initializers to a seperate interface(s). Then reference (implement) the interface in the original Java file. package oracle.dtools.ant.antlr3; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import org.apache.tools.ant.Task; public class Antlr3PostProcess extends Task { private File oldTarget = null; private String pkg = null; private File newTarget= null; private File currentInterface = null; private int interfaceInd