Skip to content

Circular grammar inclusion causes stack overflow in the tool. #2296

Closed

Description

@nikolayo

The title says it all. If G1 includes G2 etc. ... which includes G1 then the antlr tool crashes with stack overflow. It should rather print out some error diagnostics.

Here is an example tested with the version 4.7.1 of the tool :

grammar G1;
import  G2;
r  :  ;

grammar G2;
import  G1;
r  :  ;

$ antlr G1.g4
Exception in thread "main" java.lang.StackOverflowError
        at java.util.HashMap.hash(HashMap.java:339)
        at java.util.HashMap.get(HashMap.java:557)
        at org.antlr.v4.Tool.loadImportedGrammar(Tool.java:617)
        at org.antlr.v4.tool.Grammar.loadImportedGrammars(Grammar.java:391)
        at org.antlr.v4.tool.Grammar.loadImportedGrammars(Grammar.java:405)
        at org.antlr.v4.tool.Grammar.loadImportedGrammars(Grammar.java:405)
        at org.antlr.v4.tool.Grammar.loadImportedGrammars(Grammar.java:405)
        at org.antlr.v4.tool.Grammar.loadImportedGrammars(Grammar.java:405)
        ........

Activity

  1. added 3 commits that reference this issue on May 8, 2022
    7decd9f
    a1dbdb1
    8a373b6
  2. added this to the 4.10.2 milestone on Jun 25, 2022
  3. added a commit that references this issue on Jul 3, 2022
    600081e
  4. added a commit that references this issue on Jul 5, 2022
    2349068
  5. KvanTTT commented on Aug 31, 2022

    @KvanTTT
    Member

    @parrt it's fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions