Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException in LexerATNSimulator.execDFA #46

Closed
JFinis opened this issue Mar 18, 2012 · 0 comments
Closed

NullPointerException in LexerATNSimulator.execDFA #46

JFinis opened this issue Mar 18, 2012 · 0 comments

Comments

@JFinis
Copy link

JFinis commented Mar 18, 2012

I receive the following null pointer exception

line 1:1 token recognition error at: ' '
Exception in thread "main" java.lang.NullPointerException
    at org.antlr.v4.runtime.atn.LexerATNSimulator.execDFA(LexerATNSimulator.java:244)
    at org.antlr.v4.runtime.atn.LexerATNSimulator.match(LexerATNSimulator.java:155)
    at org.antlr.v4.runtime.Lexer.nextToken(Lexer.java:146)
    at org.antlr.v4.runtime.BufferedTokenStream.fetch(BufferedTokenStream.java:133)
    at org.antlr.v4.runtime.BufferedTokenStream.sync(BufferedTokenStream.java:127)
    at org.antlr.v4.runtime.CommonTokenStream.consume(CommonTokenStream.java:69)
    at org.antlr.v4.runtime.Parser.consume(Parser.java:351)
    at org.antlr.v4.runtime.Parser.match(Parser.java:135)
    at test.ANTLRv4Parser.ruler(ANTLRv4Parser.java:76)
    at Test.main(Test.java:19)

This is the used grammar (the one of issue #45)

    grammar ANTLRv4;

    ruler returns [String r]
      :  t=ID  ':' alts+=expr ('|' alts+= expr)* ';'
          {  $r = "x"; }
       ;

    strongExpr returns [String r]
      : ID                      { $r = "x"; }
      | '(' ep=parenExpr ')'            { $r = "x"; }
      | e1=strongExpr '?'             { $r = "x"; }
      ;  

    expr returns [String r]
      : e=strongExpr (e2=expr)? { $r = "x"; }
      | e1=expr '->' ID {$r = "x"; }
      ;

    parenExpr returns [String r]
      : e1=expr '|' e2=parenExpr { $r = "x"; }
      | expr              {$r = $expr.r; }
      ;

    ID  :   ('A'..'Z'|'a'..'z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*
        ;    

And here is a test input (similiar to the one of issue #45, only with spaces in between):

x : x ;

Code for parser execution:

    ANTLRv4Lexer lex = new ANTLRv4Lexer(new ANTLRInputStream(new FileInputStream(new File("test.input"))));
    CommonTokenStream tokens = new CommonTokenStream(lex);

    new ANTLRv4Parser(tokens).ruler();
parrt pushed a commit that referenced this issue Jun 30, 2015
Fix code generation support for .NET 4.5.1
parrt pushed a commit that referenced this issue Jun 30, 2015
Fix for issue #46: bug in getChild() in ParserRuleContext.
sharwell added a commit to sharwell/antlr4 that referenced this issue Dec 28, 2020
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants