There are two lines:
- An instance of the class 'ANTLRInputStream' is created as 'input';
- An instance of another LabLexer class is created as 'lexer', where the 'input' object from the previous line is passed in the constructor; The 'lexer' constructor specifies that the input argument type is CharStream, but CharStream is an interface. This interface implements the 'ANTLRStringStream' class. The latter has a successor - 'ANTLReaderStream', and it has 'ANTLRInputStream' from the first line. Problem Description: "LabLexer(org.antlr.v4.runtime.CharStream)" in "LabLexer" cannot be applied to "(org.antlr.runtime.ANTLRInputStream)" Unfortunately, I can't change the code, since it's a rather complicated tool for me - the code is written "according to the instructions." Help please!
I tried to change the type of variable - not successful. And add new constructor or change existing - not successful too (variable of CharStream type is initialized in begin of code).
CodePudding user response:
The ANTLRInputStream
class is an ANTLR v3 class. You need the v4 variant(s). Do something like this instead:
CharStream charStream = args.length > 0
? CharStreams.fromFileName(args[0])
: CharStreams.fromStream(System.in);
LabLexer lexer = new LabLexer(charStream);
LabParser parser = new LabParser(new CommonTokenStream(lexer));
CodePudding user response:
It's funny, but I quickly found a solution The type of the variable must be the name of the interface. Char input = new ANTLRInputStream(arg); instead of ANTLRInputStream input = new ANTLRInputStream(arg); Sorry for the stupid question, but I'm new to Java))