Compiling ANTLRWorks class files of generated files

I am using ANTLRWorks to create ANTLR grammars. I have the grammar correct and the parser and lexer source files are generated. I have also tried debugging the generated code and the output is as expected in the debugger output.

But when I try to call the __Test__ class generated by the debugger, nothing appears in the console. I set up the classpath correctly as I can successfully compile __Test__.java with the same class.

What is the problem? Is there a clear tutorial for writing and compiling a sample analyzer with antlr and antlrworks?

0


source to share


2 answers


What do you expect from the console?

Check out this project . The parser created by ANTLRWorks is here . As you can see from the dependencies in the POM you need to make sure antlr is on the classpath. Then you use a parser as shown in this class .



final DriftLexer lexer = new DriftLexer(new ANTLRInputStream(inputStream));
final CommonTokenStream tokens = new CommonTokenStream(lexer);        
final DriftParser parser = new DriftParser(tokens);
parser.file();

      

This should be enough for your stuff to work too.

+1


source


ANTLRWorks creates test classes that create a socket connection back to ANTLRWorks, so they cannot be used from the console. You can edit the generated test class to not use the debug port (socket) parameter.

Line to edit:

FormalSpecParser g = new FormalSpecParser(tokens, 49100, null);

      

You can change it to:



FormalSpecParser g = new FormalSpecParser(tokens, null);

      

which uses a debug destination object instead of a port, and "null" means you are not giving it a debug listener, so the debug output is ignored. You can write your own debug listener to output messages to the console.

See ANTLR documentation for more information: http://www.antlr.org/api/Java/namespaces.html

+1


source