renatahodovan / grammarinator

ANTLR v4 grammar-based test generator
Other
348 stars 62 forks source link

Is it possible to generate valid Java programs using Grammarinator? #233

Open volodya-lombrozo opened 4 months ago

volodya-lombrozo commented 4 months ago

I am trying to generate valid, compilable Java programs using Grammarinator. To achieve this, I downloaded the Java 8 ANTR Grammar and executed the following command to create a new generator:

grammarinator-process Java8Lexer.g4 Java8Parser.g4 -o fuzzer/

Next, I attempted to use this generator to produce several Java programs with the command:

grammarinator-generate Java8Generator.Java8Generator -r compilationUnit -d 20 \
  -o results/app%d.java -n 100 --sys-path fuzzer/

However, the resulting programs are invalid and cannot be compiled. Below are some examples of the generated programs:

// Example 1 
@ၡൈؓ.ꬮ۰੍.ࠏ@ߺ.ᨐ@ℓ᪅.ᠢ.ꭜ({})@ꩀৢ(ச=@ᅧ,ﹲ={},ၛ={@ቾ࠙(),},ஃ=@ᮮᢩ⁠.ⷀ.ਸ਼({{{}},}),Ῐಂꦂি=@ଡ଼.ᡐ({@ˮ᱄.ૠ,}),J={{,},})packageꮉ.ᮄ.ᝢ;importঢ়ၭే;importใ;importstaticૹ‌.ࡅ୦ᬸꩌᢆ.ਫ਼;;%                 

// Example 2 
packageὙ;

// Example 3 
packageಐ.ⸯၱඃ;importၡ.ꪱ഻;importꩀ.*;% 

As shown, the generated code is difficult to understand, and it appears that whitespaces are ignored. Is there a way to adjust the command or configuration to generate valid Java programs? Or is it fundamentally impossible to generate compilable Java programs using Grammarinator?

volodya-lombrozo commented 4 months ago

@renatahodovan Could you help, please?