general/mini/
evaluate.pro
Procedure: evaluate Purpose: This routine performs the actual evaluation of an expression in the mini_language It basically combines an slr shift/reduce parser with an evaluator Description(of how it works, super-concise version): This routine is essentially a table-driven stack machine. It uses two tables action & goto.(both are 2-d arrays) to determine how to behave at any given step. Prior states are pushed onto the stack. At each step, an action is performed, determined by the action table, and a new state is pushed onto the stack, determined by the goto table. Some actions may also pop a certain number of states off of the stack. Actions can be either shift actions or reduce actions(using reduction N). A shift action, means that it doesn't have enough tokens yet to determine the next operation, so it should process an additional token. A reduce action, means that it should perform some operation. Replacing a complex expression with a simplified expression by using one of the production rules. One more note, the stack has flexible type. Each push or pop operation generally pushes or pops two items. One will be a numerical state(long int), another will be a data item. The data items are often implemented as structs but can represent various types of items. (tokens, intermediate processing results, outputs, operators, variable identifiers) Generally the data items on the stack are anything that might be required as an input to perform a reduction. Inputs: tk_list: a list of token structures from the lex routine grammar: a grammar description structure parse_tables: a parse table structure Keywords: error: On error this routine returns a structure that describes the error that occurred $LastChangedBy: pcruce $ $LastChangedDate: 2013-05-10 17:04:22 -0700 (Fri, 10 May 2013) $ $LastChangedRevision: 12331 $ $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/spdsoft/trunk/general/mini/evaluate.pro $
Routines
File attributes
Modification date: | Thu Feb 13 16:43:51 2014 |
Lines: | 70 |