Search code examples
bisonyacclex

Is there way to generate something according to a grammar?


I want to achieve something which is reverse to parsing. If you have a set of rules, is there way/tool to generate corresponding text? For example, given a set of rules to parse maths expression, the code would automatically output maths expressions.

As I am no expert in this area, in case I post the question in wrong place (apologies in advance), please kindly offer relevant keywords or links so I can continue search.


Solution

  • I end up writing a simple parser for something like below

    E : p=0.5 E + T | p=0.5 E - T
    

    where p stands for probability.