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

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

Closed
nikolayo opened this issue May 23, 2018 · 1 comment
Closed

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

nikolayo opened this issue May 23, 2018 · 1 comment

Comments

@nikolayo
Copy link

nikolayo commented May 23, 2018

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)
        ........
aermicioi added a commit to aermicioi/antlr4 that referenced this issue May 8, 2022
Visited set is now passed across internal invocations of Grammar#loadImportedGrammars of each imported grammar, to retain the knowledge if imported sets.
aermicioi added a commit to aermicioi/antlr4 that referenced this issue May 8, 2022
Visited set is now passed across internal invocations of Grammar#loadImportedGrammars of each imported grammar, to retain the knowledge if imported sets.
aermicioi added a commit to aermicioi/antlr4 that referenced this issue May 8, 2022
Visited set is now passed across internal invocations of Grammar#loadImportedGrammars of each imported grammar, to retain the knowledge if imported sets.

Signed-off-by: aermicioi <alexandru.ermicioi@gmail.com>
@parrt parrt added this to the 4.10.2 milestone Jun 25, 2022
KvanTTT pushed a commit to KvanTTT/antlr4 that referenced this issue Jul 3, 2022
Visited set is now passed across internal invocations of Grammar#loadImportedGrammars of each imported grammar, to retain the knowledge if imported sets.

Signed-off-by: aermicioi <alexandru.ermicioi@gmail.com>
parrt pushed a commit that referenced this issue Jul 5, 2022
Visited set is now passed across internal invocations of Grammar#loadImportedGrammars of each imported grammar, to retain the knowledge if imported sets.

Signed-off-by: aermicioi <alexandru.ermicioi@gmail.com>
@KvanTTT
Copy link
Member

KvanTTT commented Aug 31, 2022

@parrt it's fixed.

@parrt parrt closed this as completed Aug 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants