_Tcl::__expression_parse ^

Given a string, return an invokable PMC that will generate the appropriate value described by this Tcl expression. An intermediate AST is generated, and the functions ends with a tailcall to the compiler.

Convert the chunks into a stack. For each level of precendence, scan the chunk list for operators that match our level. As we find one, grab the left and right operands. If the operand is null, instead use the value from the same location in the program stack as the operand (as it is the result of a previous operator.). If a value is pulled from the program_stack, then null it there.

Now that we have an operand and two operators (unary ops are treated like operands during the parse phase. Ternary op is currently ignored, but we'd special case it here.), create a TclBinaryOp, and put it in the same index in the program stack as the left op here. Replace all three entries in the chunk list with a single NULL entry.

When our list of chunks to process is a single NULL entry, we're done, and now have a program list containing a single element, which is something which supports compile. (In most cases, a TclBinaryOp)

_Tcl::__expression_compile ^

Given the AST generated by the expression parser, render the various operands as PIR.


parrot