Giter Site home page Giter Site logo

Comments (10)

sharwell avatar sharwell commented on May 5, 2024

Do you happen to know which commit you're using? (Ideally the SHA hash for it)

from antlr4.

JFinis avatar JFinis commented on May 5, 2024

Yes, it is
28ee391
from parrt/antlr4

from antlr4.

sharwell avatar sharwell commented on May 5, 2024

Can you add the following assertions to track down the source of failure?

In the two ATNConfig constructors that set state and semanticContext, add:

assert state != null;
assert semanticContext != null;

from antlr4.

JFinis avatar JFinis commented on May 5, 2024

okay, here we go:

Exception in thread "main" java.lang.AssertionError: state is null
    at org.antlr.v4.runtime.atn.ATNConfig.<init>(ATNConfig.java:112)
    at org.antlr.v4.runtime.atn.ATNConfig.<init>(ATNConfig.java:98)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.actionTransition(ParserATNSimulator.java:1043)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.getEpsilonTarget(ParserATNSimulator.java:1032)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.closure(ParserATNSimulator.java:990)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.closure(ParserATNSimulator.java:1012)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.closure(ParserATNSimulator.java:1012)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.closure(ParserATNSimulator.java:1012)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.closure(ParserATNSimulator.java:1012)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.closure(ParserATNSimulator.java:1012)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.closure(ParserATNSimulator.java:1012)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.closure(ParserATNSimulator.java:1012)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.closure(ParserATNSimulator.java:1012)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.closure(ParserATNSimulator.java:1012)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.closure(ParserATNSimulator.java:1012)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.closure(ParserATNSimulator.java:1012)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.closure(ParserATNSimulator.java:1012)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.closure(ParserATNSimulator.java:946)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.closure(ParserATNSimulator.java:1012)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.closure(ParserATNSimulator.java:1012)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.closure(ParserATNSimulator.java:912)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.computeReachSet(ParserATNSimulator.java:711)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.execATN(ParserATNSimulator.java:521)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.predictATN(ParserATNSimulator.java:331)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.adaptivePredict(ParserATNSimulator.java:296)
    at org.eeve.antlrgen.parser.ANTLRv4Parser.strongExpr(ANTLRv4Parser.java:886)
    at org.eeve.antlrgen.parser.ANTLRv4Parser.expr(ANTLRv4Parser.java:1146)
    at org.eeve.antlrgen.parser.ANTLRv4Parser.grammarRule(ANTLRv4Parser.java:398)
    at org.eeve.antlrgen.parser.ANTLRv4Parser.gramma(ANTLRv4Parser.java:150)
    at org.eeve.antlrgen.ANTLRGenTest.parseStatic(ANTLRGenTest.java:92)
    at org.eeve.antlrgen.ANTLRGenTest.main(ANTLRGenTest.java:38)

from antlr4.

sharwell avatar sharwell commented on May 5, 2024

It would definitely help if you are able to post an example grammar and input for me to duplicate this issue. You may not have to post input - it looks like you have a case where Transition is being constructed with target==null. You could add an assertion to the Transition constructor as a check.

Have you tried regenerating the code?

from antlr4.

JFinis avatar JFinis commented on May 5, 2024

Okay, here is the grammar

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:

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

from antlr4.

sharwell avatar sharwell commented on May 5, 2024

Thanks, that's perfect. I was able to derive the following grammar as a unit test for the issue which I'm now working to fix.

grammar T;
start
  : ID ':' expr
  ;
expr
  : primary expr? {}
  | expr '->' ID
  ;
primary
  : ID
  ;

ID : [a-z]+;

Input: x:x

from antlr4.

JFinis avatar JFinis commented on May 5, 2024

well, after merging your commits, I get the anticipated exception during parser building

    [java] Exception in thread "main" java.lang.IllegalStateException: Cannot serialize a transition to a removed state.
    [java]  at org.antlr.v4.automata.ATNSerializer.serialize(ATNSerializer.java:138)
    [java]  at org.antlr.v4.automata.ATNSerializer.getSerialized(ATNSerializer.java:281)
    [java]  at org.antlr.v4.codegen.model.SerializedATN.<init>(SerializedATN.java:43)
    [java]  at org.antlr.v4.codegen.model.Parser.<init>(Parser.java:86)
    [java]  at org.antlr.v4.codegen.ParserFactory.parser(ParserFactory.java:54)
    [java]  at org.antlr.v4.codegen.OutputModelController.parser(OutputModelController.java:145)
    [java]  at org.antlr.v4.codegen.OutputModelController.buildParserOutputModel(OutputModelController.java:84)
    [java]  at org.antlr.v4.codegen.CodeGenerator.generateParser(CodeGenerator.java:132)
    [java]  at org.antlr.v4.codegen.CodeGenPipeline.process(CodeGenPipeline.java:51)
    [java]  at org.antlr.v4.Tool.processNonCombinedGrammar(Tool.java:353)
    [java]  at org.antlr.v4.Tool.process(Tool.java:319)
    [java]  at org.antlr.v4.Tool.processGrammarsOnCommandLine(Tool.java:283)
    [java]  at org.antlr.v4.Tool.main(Tool.java:173)

While this is better than a fail at runtime, it is still not satisfactory, as I don't know what I have done wrong.

from antlr4.

sharwell avatar sharwell commented on May 5, 2024

Once this issue is corrected, it will be tagged with "status:pull-request" until it gets closed. :) The test I've implemented so far is in place to help track down the issue, but like you saw it doesn't create a working grammar.

from antlr4.

sharwell avatar sharwell commented on May 5, 2024

I am no longer able to reproduce this bug.

from antlr4.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.