Class OperandStack
java.lang.Object
EDU.purdue.cs.bloat.tree.OperandStack
OperandStack is used to simulate the JVM stack. A stack of
expressions is maintained. OperandStack has methods to push and
pop (both wide and non-wide) expressions, replace an expression at a given
depth in the stack, peek into the stack, etc.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionget(int index) Returns the expression at index from the bottom of the stack.intheight()booleanisEmpty()peek()Returns the expression at the top of the stack, but does not modify the stack.peek(int depth) Get the expression that is depth expressions from the top of the stack, but do not modify the stack.Pops an operand off the stack.pop1()Pops a non-wide expression off the stack.Expr[]pop2()Pops a (possibly) wide expression off of the stack and returns the result as an array of Expr.voidPush an expression onto the stack.voidReplaces the expression that is depth expressions from the top of the stack.voidSets the entry at a specified index from the bottom of the stackintsize()Returns the number of expressions on the stack.toString()Returns a String represntation of this stack.
-
Constructor Details
-
OperandStack
public OperandStack()Constructor.
-
-
Method Details
-
isEmpty
public boolean isEmpty()- Returns:
- True, if the stack is empty.
-
pop
-
peek
Returns the expression at the top of the stack, but does not modify the stack. -
set
Sets the entry at a specified index from the bottom of the stack- Parameters:
index- The position in the stack.expr- The new value of the expression.
-
height
public int height()- Returns:
- The number of elements in the stack.
-
replace
Replaces the expression that is depth expressions from the top of the stack.- Parameters:
depth- The number of expressions from the top of the stack.expr- The new expression
-
peek
Get the expression that is depth expressions from the top of the stack, but do not modify the stack.- Parameters:
depth- Number of expressions deep to get.- Returns:
- The expression that is depth expression from the top of the stack.
-
pop1
Pops a non-wide expression off the stack. -
pop2
Pops a (possibly) wide expression off of the stack and returns the result as an array of Expr. If the expression at the top of the stack is indeed wide, it is returned in element [0] of the array. If the expression at the top of the stack is not wide, the top two expressions are returned in the array as elements 0 and 1. -
push
-
size
public int size()Returns the number of expressions on the stack. -
get
Returns the expression at index from the bottom of the stack. -
toString
-