Stack Machines, Expression Evaluation, and the Magic of Reverse Polish

To teach a friend how compilers work, I've written a compiler for a small subset of Pascal. It lexically analyses and parses a program, code-generates the syntax tree into code for a stack machine not unlike the Ocode virtual machine once used by C's ancestral language BCPL, and interprets the code. I'm going to write a few essays about the compiler and its target machine; in this first one, I'll demonstrate how a stack machine evaluates expressions.



February 21, 2010
URL:http://www.drdobbs.com/architecture-and-design/stack-machines-expression-evaluation-and/228700646

Terms of Service | Privacy Statement | Copyright © 2024 UBM Tech, All rights reserved.