Reputation: 2756
I just started with antlr, And I am using 4.2. Easy guessing says it would be like antlr3 in basics. so I followed the accepted answer of this question. (But instead of Exp, I replaced Java, which means I want to parse Java) Everything is fine, Until I want to compile the ANTLRDemo.java example.
When I compile that, I get 4 errors:
ANTLRStringStream in = new ANTLRStringStream("some random text");
JavaLexer lexer = new JavaLexer(in);
first error: constructor JavaLexer in class JavaLexer cannot be applied to given types; JavaLexer lexer = new JavaLexer(in); required: CharStream found: ANTLRStringStream reason: actual argument ANTLRStringStream cannot be converted to CharStream by method invocation conversion (I know what this error is ;-)
CommonTokenStream tokens = new CommonTokenStream( lexer);
JavaParser parser = new JavaParser(tokens);
System.out.println(parser.eval());
to make it short, let's say every line has its own similar error. For example, "parser" does not have an "eval()" method.
What am I missing? I guess antlr4 does not run like 3. Any Ideas? Please consider my beginner status.
Upvotes: 2
Views: 1145
Reputation: 100029
In ANTLR 4, use ANTLRInputStream
instead of the old ANTLRStringStream
from ANTLR 3.
The eval()
method exists when you have a parser rule in the grammar named eval
. One such method is created for each rule in the grammar. If you do not intend to start parsing at rule eval
, then you should replace that call with the name of the start rule for your particular grammar.
Upvotes: 4