Easy, stupid answer: Store program as a sequence of statements (say in a vector). When you see WHILE, push the statement number on to a stack of open WHILEs. Interpret lines until you see WHILESTOP. Return program counter to the top of the WHILE stack.
Better, more patterny answer:
(1) Assume you have a Command class. That is, there is a Command class that is responsible for INCREASE and one responsible for assignment, etc. Each overrides the operator() that applies the Command to do what it is supposed to do (you will have a fun time with parameters to ()...take a look at Command pattern in Gamma, et. al. _Design Patterns_ for ideas on that).
(2) Add a WhileCommand child; it keeps a vector of Commands and when it is applied it just goes down the list and applies each of its children before redoing the test. This is the Decorator pattern.
If this makes no sense, ask more questions. I hope that it helps,
-bcl
Main Topics
Browse All Topics





by: griesshPosted on 2005-01-21 at 12:44:08ID: 13106659
Hi njava,
/obidos/tg /detail/-/ 0201403536 / qid=11063 40205/sr=1 -1/ref=sr_ 1_1/103-20 14278-3335 820? v=glan ce&s=books
Compiler design is no joy ride:-) If you don't have experience in that area you need to learn some basics. The Grand Master of Compiler Design, Niklas Wirth has written a book that might help you to understand the problems. Check out http://www.amazon.com/exec
======
Werner