Semantic stack

Rasmus Anthin <e8rasmus@etek.chalmers.se>
21 May 2001 02:03:48 -0400

          From comp.compilers

Related articles
Semantic stack e8rasmus@etek.chalmers.se (Rasmus Anthin) (2001-05-21)
| List of all articles for this month |

From: Rasmus Anthin <e8rasmus@etek.chalmers.se>
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?


Sincerely,




//B. Rasmus Anthin.


e8rasmus@etek.chalmers.se
http://www.etek.chalmers.se/~e8rasmus
[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.