How to generate random code with antlr4?

44 views
Skip to first unread message

Samuel Leonardo

unread,
Jan 13, 2024, 2:36:25 PMJan 13
to antlr-discussion
Hello,
I've searched for something like this:
--suppose I have a JS3's grammar
so, how can I generate a well formed random code in which the code runs without problem?
For example: instead of get the tokens from a source, I want to make a valid tree with the random rules.

My difficult was that I can't found someone making something like this.

I tried to construct the parsetree, but I found that is not possible cause the tree is read-only.

So, did anyone make something in this sense and can give me a sense of what to do?

Thanks

Susan Jolly

unread,
Jan 13, 2024, 3:48:58 PMJan 13
to antlr-di...@googlegroups.com
As the ANTLR4 book  explains when a parser is generated a template for something like a listener is also generated.
 There are examples  in the book for how to set up a main prugram to hook the parts  together so you can feed a lexer with whatever  and analyze its partsetree by exrending the template.
HTH 
On Jan 13, 2024, at 11:36 AM, Samuel Leonardo <samuel.l...@gmail.com> wrote:


--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/antlr-discussion/cc507846-d2e1-4e85-9a1d-dc5ce4992587n%40googlegroups.com.

Ken Domino

unread,
Jan 13, 2024, 9:17:25 PMJan 13
to antlr-discussion
Check out Grammarinator, https://github.com/renatahodovan/grammarinator.

Please use StackOverflow for questions.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages