Semantic stack

Rasmus Anthin <>
21 May 2001 02:03:48 -0400

          From comp.compilers

Related articles
Semantic stack (Rasmus Anthin) (2001-05-21)
| List of all articles for this month |

From: Rasmus Anthin <>
Newsgroups: comp.compilers
Date: 21 May 2001 02:03:48 -0400
Organization: Chalmers University of Technology
Keywords: parse, practice, question, comment
Posted-Date: 21 May 2001 02:03:48 EDT

To perform semantics for a given grammar, say a calculator-grammar, how do
you implement the semantic stack. Do you stack the operators and operands
in an infix way "on the fly" while parsing, or do you first construct the
tree and then traverse this tree while stack the operands and operators
performing calculations (poping the stack) for each level in the tree
then pushing the result to the stack in the level above in a recursive
way? Which way is easiest? Is there another way of doing this or have I
totally missed the idea of translating a parse-tree?


//B. Rasmus Anthin.
[It depends on how fancy the language is. If it's really just an expression
evaluator, you can do the operations on the fly. If it has any kind of
looping or flow of control, it's easier to parse the whole thing, then
interpret it. -John]

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.