Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Just doing string substitution is the wrong way to go about this. Use Recursive-Descent Parsing instead</p> <p>First you want to define what symbols create what for example:</p> <blockquote> <p>program -> LiteralArg|fn(x)|program</p> <p>LiteralArg -> LiteralArg</p> <p>LiteralArg&amp;LiteralArg -> fn(LiteralArg) &amp; fn'(LiteralArg)</p> <p>fn(x) -> fn(x)</p> <p>fn(x) |fn(y) -> fn(x),fn(y)</p> </blockquote> <p>From there you make functions which will recursively parse your data expecting certain things to happen. For example</p> <pre><code> String finalResult = ""; function parse(baseString) { if(basestring.isLiteralArg) { if(peekAheadToCheckForAmpersand()) { expectAnotherLiteralArgAfterAmpersandOtherwiseThrowError(); finalResult += fn(LiteralArg) &amp; fn'(LiteralArg) parse(baseString - recentToken); } else { finalResult += literalArg; parse(baseString - recentToken); } } else if(baseString.isFunction() { if(peekAheadToCheckForPipe()) { expectAnotherFunctionAfterAmpersandOtherwiseThrowError(); finalResult += fn(x),fn(y) parse(baseString - recentToken); } else { finalResult += fn(x) parse(baseString - recentToken); } } } </code></pre> <p>As you find tokens, take them off the string and call the parse function on the remaining string.</p> <p>Rough example which I'm basing off a project I did years ago. Here is the relevant lecture: <a href="http://faculty.ycp.edu/~dhovemey/fall2009/cs340/lecture/lecture7.html" rel="nofollow">http://faculty.ycp.edu/~dhovemey/fall2009/cs340/lecture/lecture7.html</a></p>
 

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