Makan
Makan

Reputation: 2756

antlr 4.2 difficulty using Parser

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);

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

Answers (1)

Sam Harwell
Sam Harwell

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

Related Questions