Any tools can randomly generate the source code according to a language grammar?

Posted by wbsun on Stack Overflow See other posts from Stack Overflow or by wbsun
Published on 2010-12-17T05:54:13Z Indexed on 2011/01/05 14:54 UTC
Read the original article Hit count: 133

Filed under:
|
|

A C program source code can be parsed according to the C grammar(described in CFG) and eventually turned into many ASTs. I am considering if such tool exists: it can do the reverse thing by firstly randomly generating many ASTs, which include tokens that don't have the concrete string values, just the types of the tokens, according to the CFG, then generating the concrete tokens according to the tokens' definitions in the regular expression.

I can imagine the first step looks like an iterative non-terminals replacement, which is randomly and can be limited by certain number of iteration times. The second step is just generating randomly strings according to regular expressions.

Is there any tool that can do this?

© Stack Overflow or respective owner

Related posts about compiler

Related posts about random-generator