aboutsummaryrefslogtreecommitdiff
path: root/stack.go
diff options
context:
space:
mode:
Diffstat (limited to 'stack.go')
-rw-r--r--stack.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/stack.go b/stack.go
new file mode 100644
index 0000000..c0850d4
--- /dev/null
+++ b/stack.go
@@ -0,0 +1,27 @@
+package expression
+
+type Stack []Token
+
+func (s *Stack) Push(item Token) {
+ *s = append(*s, item)
+}
+
+func (s *Stack) Pop() (item Token) {
+ if len(*s) == 0 {
+ return
+ }
+
+ *s, item = (*s)[:len(*s)-1], (*s)[len(*s)-1]
+ return item
+}
+
+func (s *Stack) Empty() bool {
+ return len(*s) == 0
+}
+
+func (s *Stack) Head() (item *Token) {
+ if s.Empty() {
+ return nil
+ }
+ return &((*s)[len(*s)-1])
+}