I am trying out a project using ANTLR4 and I'm following this tutorial and this question.
The following is my Drink.java file
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.tree.*;
import static org.antlr.v4.runtime.CharStreams.fromFileName;
public class Drink {
public static void main (String [] args) {
CharStream cs = fromFileName("test.txt"); //load the file
DrinkLexer lexer = new DrinkLexer(cs); //instantiate a lexer
CommonTokenStream tokens = new CommonTokenStream(lexer); //scan stream for tokens
DrinkParser parser = new DrinkParser(tokens); //parse the tokens
ParseTree tree = parser.drinkSentence(); // parse the content and get the tree
DrinkWalker listener = new DrinkWalker();
ParseTreeWalker walker = new ParseTreeWalker();
walker.walk(listener,tree);
}
}
and the following is my DrinkWalker.java file
public class DrinkWalker extends DrinkBaseListener {
@Override public void enterEveryRule(ParserRuleContext ctx) {
System.out.println("rule entered: " + ctx.getText());//code that executes per rule
}
public void enterR(DrinkParser.RContext ctx ) {
System.out.println( "Entering R : " + ctx.ID().getText() );
}
public void exitR(DrinkParser.RContext ctx ) {
System.out.println( "Exiting R" );
}
}
I compiled them manually, and I get the following errors:
Override public void enterEveryRule(ParserRuleContext ctx) {
^
symbol: class ParserRuleContext
location: class DrinkWalker
DrinkWalker.java:5: error: cannot find symbol
public void enterR(DrinkParser.RContext ctx ) {
^
symbol: class RContext
location: class DrinkParser
DrinkWalker.java:9: error: cannot find symbol
public void exitR(DrinkParser.RContext ctx ) {
^
symbol: class RContext
location: class DrinkParser
What are the RContext and ParserRuleContext functions referred above?