Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling ISO SQL-2003 ANTLR Grammar

I am trying to compile the ISO-SQL 2003 grammar from here http://www.antlr3.org/grammar/1304304798093/SQL2003_Grammar.zip. All three versions of it can be found here http://www.antlr3.org/grammar/list.html.

These are the steps I followed,

  1. java -jar antlr-3.3-complete.jar -Xmx8G -Xwatchconversion sql2003Lexer.g
  2. java -jar antlr-3.3-complete.jar -Xmx8G -Xwatchconversion sql2003Parser.g
  3. 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();
   }
}

First two steps work fine, then while compiling my main class I get a lot of errors related to Java syntax like these:

./sql2003Parser.java:96985: error: not a statement $UnsignedInteger.text == '1' ./sql2003Parser.java:96985: error: ';' expected $UnsignedInteger.text == '1' ./sql2003Parser.java:102659: error: unclosed 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 can show me how exactly to setup this grammar using ANTLR.

Edit: After a little more fiddling, I think that these errors are caused by the actions present in lexer and parser rules. Is there a safe way to overcome this?

like image 784
noob333 Avatar asked Dec 10 '15 13:12

noob333


1 Answers

You are not doing anything wrong, ANTLR has never been able to generate a working Java parser from these grammar files.

According to a post by Douglas Godfrey to antlr-interest in Oct 2011:

I generated a C parser and lexer. they both generate and compile successfully on my machine with 8GB heap allocated to Antlr.

...

I don't believe that it will ever be possible to get a working parser in Java. A C language parser on the other hand is quite possible.

like image 178
anttix Avatar answered Oct 07 '22 02:10

anttix