I'm trying to use Antlr v4 to generate a lexer and parser for a simple custom grammar. The issue is that when I run the Antlr .jar utility, it generates a Lexer file but not a Parser file too, as I think it should.
Simple grammar
// Define a grammar called Hello
grammar Hello;
r : 'hello' ID ; // match keyword hello followed by an identifier
ID : [a-z]+ ; // match lower-case identifiers
WS : [ \t\r\n]+ -> skip ; // skip spaces, tabs, newlines
Antlr tool
Following along with these instructions: https://github.com/antlr/antlr4/blob/master/doc/tool-options.md. The Java tool can be downloaded from http://www.antlr.org/download/index.html (I selected the antlr-4.7-complete.jar).
Let's generate the lexer and parser: antlr.jar -o outDir -Dlangage=JavaScript -visitor -listener test.g4
Actual output
- HelloLexer.js
- HelloLexer.tokens
Desired output
- HelloLexer.js
- HelloParser.js
- HelloListener.js
- HelloVisitor.js
I'd like the parser because once I have lexed the input, I want to parse and generate a tree which I can then traverse, as illustrated in this tutorial:
var input = "your text to parse here"
var chars = new antlr4.InputStream(input);
var lexer = new MyGrammarLexer.MyGrammarLexer(chars);
var tokens = new antlr4.CommonTokenStream(lexer);
var parser = new MyGrammarParser.MyGrammarParser(tokens);
// ^ [!] notice here how I don't have an analogous "HelloParser.js" to run my tokens through!
parser.buildParseTrees = true;
var tree = parser.MyStartRule();
How do I get the Antlr tool to generate the HelloParser.js file I want? Right now it is only generating the Lexer, and the tutorials I have followed (links above) do not have any details for the situation I am in.