blob: c1046ee92b2318577679b7d741f377f0a475a385 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
package sableCCCalculator;
import sableCCCalculator.types.*;
import java.util.Stack;
public class ProgramStack<T extends Type> extends Stack<T> {
public String toString() {
String out = "Stack is now: [";
for (int i = 0; i < this.size(); i++) {
// String theStr = this.elementAt(i).toString();
// out += String.format("%s, ", theStr.substring(0, theStr.length() - 1));
out += String.format("%s, ", this.elementAt(i).toString());
}
return out.substring(0, out.length() - 2) + "]";
}
public static void main(String[] args) {
ProgramStack<Type> myStack = new ProgramStack<>();
myStack.add(new Int(2));
myStack.add(new Int(4));
myStack.add(new Int(6));
myStack.add(new Int(0));
myStack.add(new Int(1));
myStack.add(new Decimal(24601.10642));
System.out.println(myStack.pop().getText());
System.out.println(myStack);
}
}
|