0

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.

user180574
  • 5,681
  • 13
  • 53
  • 94
  • Here's one near duplicate: https://stackoverflow.com/questions/50036110/how-to-generate-random-programs-from-bnf – rici Nov 07 '18 at 22:30
  • Also, Google found me lots of stuff using the search `generating sentences from grammar` – rici Nov 07 '18 at 22:34

2 Answers2

0

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.

user180574
  • 5,681
  • 13
  • 53
  • 94
-1

I'm not an expert in this area, and I don't really know of anything that does exactly what you're asking.

However, maybe look into using a recurrent neural network. Karpathy's blog post is excellent and it has some examples of a rnn writing in Shakespeares style or even generating valid XML. Karpathy's blog

Maybe that could help? You can train it on the rules you want to follow and it may come up with some creative writing within those rules.

LDN
  • 29
  • 4