I am trying to compile an ISO-SQL 2003 grammar here http://www.antlr3.org/grammar/1304304798093/SQL2003_Grammar.zip . All three versions can be found here http://www.antlr3.org/grammar/list.html .
These are the steps that I followed
- java -jar antlr-3.3-complete.jar -Xmx8G -Xwatchconversion sql2003Lexer.g
- java -jar antlr-3.3-complete.jar -Xmx8G -Xwatchconversion sql2003Parser.g
- javac ANTLRDemo.java
ANTLRDemo.java file:
import org.antlr.runtime.*; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; public class ANTLRDemo { static String readFile(String path) throws IOException { byte[] encoded = Files.readAllBytes(Paths.get(path)); return new String(encoded, "UTF-8"); } public static void main(String[] args) throws Exception { ANTLRStringStream in = new ANTLRStringStream( readFile(args[0]) ); sql2003Lexer lexer = new sql2003Lexer(in); CommonTokenStream tokens = new CommonTokenStream(lexer); sql2003Parser parser = new sql2003Parser(tokens); parser.eval(); } }
The first two steps work fine, then when compiling my main class I get a lot of errors related to Java syntax, like these:
./sql2003Parser.java:96985: error: not approval $ UnsignedInteger.text == '1'. / sql 2003Parser.java:96985: error: ';' expected $ UnsignedInteger.text == '1'. / sql 2003Parser.java:102659: error: open character literal if (! ((((Unsigned_Integer3887! = null? Unsigned_Integer3887.getText (): null) == '01'))) {
Please let me know if I am doing something wrong in setting up the parser.
It would be helpful if someone could show me exactly how to tune this grammar with ANTLR.
Edit: after a bit more trivial, I think these errors are caused by the actions contained in the lexer and parser rules. Is there a safe way to overcome this?
java sql parsing antlr
noob333
source share