Comments
Loading Dream Comments...
You must be logged in to write a comment - Log In
Artist
Parser <:: { (input=%, tree=(), state=0, action=&{()}, node, token); {* #input :
{input => token; action <:: table[token][state]; state <:: next[token][state]; action()}
*}; tree}
// Note that the implementation below is now obsolete, since we now use a State Machine Parser rather than a Recursive Descent Parser
**********
\\ Parser <:: { (input=%, tree=(), subtree=(), token1, token2, token3 ); {* #input : // repeat while input isn't empty
{ input => token1; {(), subtree <:: Parser(input);} [1+(token1 == "(")]; // Open parenthesis, so do recursive descent
{input => token2 => token3; // Pop from head of input
{(), {tree << (token1, token2, subtree)}}[1 + (isOperand(token1) /\ isOperator(token2) /\ #subtree)]; // Dyadic with subtree
{(), {tree << (token1, token2, token3)}}[1+ (isOperand(token1) /\ isOperator(token2) /\ isOperand(token3)]; // Dyadic operator
// Note we put back token3 if not used below
{(), {tree << (token1, token2); input < token3}}[1+ (isOperator(token1) /\ isOperand(token2)]; // Monadic operator
// More stuff here, for example we need to do PEMDAS priorities, parentheses, semicolons, and vectors
*} // End loop when no more input
tree} // The function returns the parse tree :) \\
**********
Note the new alternative comment delimiters : "\\"
We can enclose a block of code between a pair of "\\"'s, when encountered they alternately switch off and on code activity, just like "#ifdef" / "#else" / "#endif" :) By adding another "\\" we can reverse the sense of activation of a block, since now the new "\\" matches the first, and the code between them is enabled again :)