2 ms·
If you instead flatten the expression tree into RPN, then you can execute it like that, with a stack machine. I seem to recall that the Red Dragon Book (Compil
by kazinator 2y ago
If you instead flatten the expression tree into RPN, then you can execute it like that, with a stack machine.
I seem to recall that the Red Dragon Book (Compilers: Principles, Techniques and Tools, Aho, Sethi, Ullman [1988]) describes a technique whereby intermediate code is represented in RPN, and transformations are performed by pattern matches on it.
- finnh 2y agoThe sample flat program in the post is exactly RPN, no?
- samps 2y agoI think it would be more like RPN if it used a stack, and operands were specified as relative offsets (i.e., stack offsets). In the version I wrote, operands are still represented as absolute offsets in the expression table.