ANTLR3 throws internal error with java.lang.NullPointerException

前端 未结 1 1864
余生分开走
余生分开走 2021-01-16 22:34

I tried to use ANTLR3 to build a simple Regexpression parser, but it throws the internal error

Here is the Sample.g

grammar Sample;

options {
    me         


        
相关标签:
1条回答
  • 2021-01-16 23:04

    You're trying to use a rewrite rule (tree construction) on a lexer rule. That doesn't make sense.

    In ANTLR, all rules with name starting with an uppercase letter are lexer rules. The tree construction is used on AST nodes, not on tokens themselves, so you have to use it on parser rules (starting with lowercase letter).

    When you do that, keep in mind that your NL is a fragment now (you cannot use fragments in parser rules) and make sure your ANY token doesn't collide with anything else, i.e. define all needed tokens (/, NL etc.) and put them above the ANY token definition.

    0 讨论(0)
提交回复
热议问题