Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>C (parsing+matching) <strike>727</strike> 670 chars</h2> <p>This is not fully golfed to the bare minimum yet, but I wanted to try and see if parsing the regexp first would make a difference to interpreting it live. It does, because it costs more, although both parsing and matching are easier to write/understand.</p> <pre><code>#define Q struct q #define C char #define R return Q{Q*u,*n,*a;C c,m};Q*P(C*p,C*e){Q*r=calloc(99,1);C*n=p+1,c=1,w;if(p==e)R r;if(*p==40){for(;c;)c+=(*n==40)-(*n++==41);r-&gt;u=P(p+1,n-1);}else if(*p=='|'){r-&gt;a=P(p+1,e);R r;}else r-&gt;c=*p;if(n&lt;e){if(*n==43)*n=42,r-&gt;n=P(p,e);else w=*n==42|*n==63,r-&gt;n=P(n+w,e),r-&gt;m=w?*n:0;r-&gt;a=r-&gt;n-&gt;a;}R r;}M(Q*r,C*s,C*o,C*z){C*p, e;e=r?r-&gt;m==63|r-&gt;m==42&amp;&amp;M(r-&gt;n,s,o,z)?:*s&amp;&amp;r-&gt;c==*s?M(r-&gt;m==42?r:r-&gt;n,s+1,o,z):2:s ==z;if(e-2)R e;for(p=s,e=0;!r-&gt;c&amp;p&lt;=z;p++)e|=M(r-&gt;u,s,s,p)&amp;(r-&gt;m!=42|p&gt;s)&amp;&amp;M(r-&gt;m== 42?r:r-&gt;n,p,p,z);R e||r-&gt;a&amp;&amp;M(r-&gt;a,o,o,z);}main(C c,C**v){for(;--c&gt;1;)puts(M(P(v[1],index(v[1],0)),v[c],v[c],index(v[c],0))?"true":"false");} </code></pre> <p>it parses a regexp into a struct, where each struct has:</p> <ul> <li>the character to be matched <em>or</em> a pointer to a struct of a subpattern to be matched</li> <li>a pointer to the next symbol struct (if any)</li> <li>a pointer to the next alternative pattern (if any)</li> <li>a multiplier which is \0, <code>*</code> or <code>?</code> -- <code>(pat)+</code> is parsed into <code>(pat)(pat)*</code> right away which makes matching far easier</li> </ul>
    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. 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