Note that there are some explanatory texts on larger screens.

plurals
  1. POFormal languages generator?
    primarykey
    data
    text
    <p>I'm wondering if there exists a library (preferably in .NET) for generating outputs based on formal grammars.</p> <p>I'm talking about this: <a href="https://en.wikipedia.org/wiki/Chomsky_hierarchy#Formal_grammars" rel="nofollow">https://en.wikipedia.org/wiki/Chomsky_hierarchy#Formal_grammars</a></p> <p>So you give it the grammar as in:</p> <p>(Non-terminal symbols, Terminal symbols, Production rules, Start symbol)</p> <p>so:</p> <pre><code>Grammar = ({E,A,B}, {(,),a,+,*}, P, E); Where P = { E -&gt; A, E -&gt; E + A, A -&gt; B, A -&gt; A * B, B -&gt; a, B -&gt; (E) }; </code></pre> <p>And then the library would produce example random outputs of that grammar like:</p> <pre><code>a * a + a a + (a + a) a * a * a </code></pre> <p>What I'm going to do after either creating or finding a library like this is to then change the way it produces the output to make it more biased to produce certain examples more than others, so in the previous example I can make it more biased to produce more expressions with addition in them rather than multiplication.</p> <p>So basically assign weights to production rules to make some of them more likely to get applied when there is more than one valid.</p> <p>So my main question is, is there a library out there that can do the first step which is producing random outputs based on a formal grammar like my example?</p> <p><strong>Update</strong></p> <p>Thinking about this problem again, I have a few more notes:</p> <ul> <li><p>One of the problems here is to know when to stop applying production rules. Either make sure that the grammar does stop at some point or devise a way in the algorithm/code that makes it less likely to keep expanding the expression further on.</p></li> <li><p>I realise now that this might be too theoretical and there is probably a more practical way. I mean, there have to be some tools out there that essentially do this same thing but maybe just use a different syntax or approach that is more specific to certain problems or maybe something more flexible.</p></li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload