Reputation: 59
I have an antlr4 based project with a Main class containing this code:
package com.progur.langtutorial;
import java.io.FileInputStream;
import java.io.IOException;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
public class Main {
@SuppressWarnings("deprecation")
public static void main(String[] args) {
try {
CharStream input = CharStreams.fromString("test");
GYOOLexer lexer = new GYOOLexer(input);
GYOOParser parser = new GYOOParser(new CommonTokenStream(lexer));
parser.addParseListener(new MyListener());
// Start parsing
parser.program();
} catch (IOException e) {
e.printStackTrace();
}
}
}
However, I am having an error in parser.addParseListener(new MyListener()); where it says MyListener cannot be resolved to a type
. What could that mean? In every tutorial I looked there was a random name for where 'MyListener()' is. What should be the correct statement for this?
Thanks!
Upvotes: 0
Views: 595
Reputation: 370192
The listener that you pass to addParseListener
should be a class that you defined yourself (and which implements the GYOOListener
interface or extends the GYOOBaseListener
abstract class generated by ANTLR). If you did not define a listener class, there's no reason to call addParseListener
.
Upvotes: 1