aboutsummaryrefslogtreecommitdiff
path: root/stack.go
diff options
context:
space:
mode:
authorAlexander Kiryukhin <a.kiryukhin@mail.ru>2022-06-13 04:31:31 +0300
committerAlexander Kiryukhin <a.kiryukhin@mail.ru>2022-06-13 04:31:31 +0300
commit05626592208f56d88523887e2b80c0514f8ac210 (patch)
treeb0db34890e7366008754e975a8f28e878c5b28bf /stack.go
initial
Diffstat (limited to 'stack.go')
-rw-r--r--stack.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/stack.go b/stack.go
new file mode 100644
index 0000000..5f60315
--- /dev/null
+++ b/stack.go
@@ -0,0 +1,23 @@
+package lexpr
+
+type TokenStack []Token
+
+func (s *TokenStack) Push(item Token) {
+ *s = append(*s, item)
+}
+
+func (s *TokenStack) Pop() (item Token) {
+ if len(*s) == 0 {
+ return
+ }
+
+ *s, item = (*s)[:len(*s)-1], (*s)[len(*s)-1]
+ return item
+}
+
+func (s *TokenStack) Head() (item Token) {
+ if len(*s) == 0 {
+ return
+ }
+ return (*s)[len(*s)-1]
+}