Machine-translated by Google. Questions are authored in English.
Top

Discussion

Emitting code for a stack machine from an expression tree amounts to

  • A.a search of the tree for the deepest subexpression
  • B.a postorder traversal pushing operands and applying operators
  • C.a preorder traversal emitting the operators first
  • D.a breadth first traversal of the successive levels of the tree

Answer: B

Each leaf becomes a push and each interior node an operator that consumes the values pushed by its children. The result is exactly reverse Polish order. No register allocation is required, which is what makes the model so simple.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.