NAME ^

Tcl Expressions

DESCRIPTION ^

This is the parser that deals with all [expr] related code. (Include those used implicitly by commands like [while].

FUNCTIONS ^

(int register_num, string pir_code) = __expression_compile(int register_num, string expr)

Argument register_num is the first register number that is available for use by the generated PIR.

Return register_num is the register number that contains the result of this code.

(pmc ast) = __expression_ast(string expr)

Given a string representing a tcl [expr], return a PMC that represents the abstract syntax tree associated with this expression.

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)


parrot