Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you are just talking about regular expressions from a theoretical point of view, there are these three constructs:</p> <pre><code>ab # concatenation a|b # alternation a* # repetition or Kleene closure </code></pre> <p>What you could then just do:</p> <ul> <li>create a rule <code>S -&gt; (fullRegex)</code></li> <li>for every repeated term <code>(x)*</code> in <code>fullRegex</code> create a rule <code>X -&gt; x X</code> and <code>X -&gt; ε</code>, then replace <code>(x)*</code> with <code>X</code>.</li> <li>for every alternation <code>(a|b|c)</code> create rules <code>Y -&gt; a</code>, <code>Y -&gt; b</code> and <code>Y -&gt; c</code>, then replace <code>(a|b|c)</code> with <code>Y</code></li> </ul> <p>Simply repeat this recursively (note that all <code>x,</code> <code>a</code>, <code>b</code> and <code>c</code> can still be complex regular expressions). Note that of course you have to use unique identifiers for every step.</p> <p>This should be enough. This will certainly not give the most elegant or efficient grammar, but that is what normalization is for (and it should be done in a separate step and there are <a href="http://en.wikipedia.org/wiki/Chomsky_normal_form#Converting_a_grammar_to_Chomsky_Normal_Form" rel="noreferrer">well-defined steps</a> to do this).</p> <p>One example: <code>a(b|cd*(e|f)*)*</code></p> <pre><code>S -&gt; a(b|cd*(e|f)*)* S -&gt; a X1; X1 -&gt; (b|cd*(e|f)*) X1; X1 -&gt; ε S -&gt; a X1; X1 -&gt; Y1 X1; X1 -&gt; ε; Y1 -&gt; b; Y1 -&gt; cd*(e|f)* S -&gt; a X1; X1 -&gt; Y1 X1; X1 -&gt; ε; Y1 -&gt; b; Y1 -&gt; c X2 (e|f)*; X2 -&gt; d X2; X2 -&gt; ε ... and a few more of those steps, until you end up with: S -&gt; a X1 X1 -&gt; Y1 X1 X1 -&gt; ε Y1 -&gt; b Y1 -&gt; c X2 X3 X2 -&gt; d X2 X2 -&gt; ε X3 -&gt; Y2 X3 X3 -&gt; ε Y2 -&gt; e Y2 -&gt; f </code></pre>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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