Code Monkey home page Code Monkey logo

Comments (4)

OctavioGalland avatar OctavioGalland commented on July 19, 2024 1

I've tried the new commit and it worked great.
I had thought this might be related to antlr since afl hanged when calling antlr4::DefaultErrorStrategy::sync, but I wasn't aware of the fact that ambiguous grammar rules could cause trouble.

Thank you so much for your help!

from grammar-mutator.

h1994st avatar h1994st commented on July 19, 2024

I will take a look later this week.

from grammar-mutator.

h1994st avatar h1994st commented on July 19, 2024

My guess is that your python grammar has inappropriate recursive rules. For example,

"<program>": [["<stmt>", "<NEWLINE>"], ["<stmt>", "<NEWLINE>", "<program>"]],
"<decorators>": [["<decorator>"], ["<decorator>", "<decorators>"]],

The two rules for <program> may result in ambiguity, as they look quite similar. There may exist other recursive rules in your grammar.

I would change them to the following rules to avoid ambiguity:

"<program>": [["<stmt>", "<NEWLINE>", "<program>"], []],
"<decorators>": [["<decorator>", "<decorators>"], []],

This is just my guess, and need to check ANTLR4 documents for more information.

from grammar-mutator.

h1994st avatar h1994st commented on July 19, 2024

Hi @OctavioGalland

A temporary workaround is pushed: 4899a2f. You can give it a try.

The new commit fixes a naming issue. Since you are using the grammar generator to generate test cases, the new commit can help you avoid parsing during the initialization stage.

Still, the issue is not fully resolved, as it is actually caused by the ambiguity of the grammar. You can also confirm the infinite loop behavior using ANTLR4:

python grammars/f1_g4_translate.py ./grammars/python.json ./grammars  # Generate Grammar.g4
mkdir temp
cd temp
java -jar ../antlr-4.8-complete.jar ../grammars/Grammar.g4
javac -cp "../antlr-4.8-complete.jar:$CLASSPATH" Grammar*.java

java -cp "../antlr-4.8-complete.jar:$CLASSPATH" org.antlr.v4.gui.TestRig Grammar entry -tree -trace ../in/0
# the program will hang here

To fully address your issue, you may want to reach out to the ANTLR4 community for help to diagnose the root cause of the grammar.

from grammar-mutator.

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.