diff options
author | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2022-06-13 04:31:31 +0300 |
---|---|---|
committer | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2022-06-13 04:31:31 +0300 |
commit | 05626592208f56d88523887e2b80c0514f8ac210 (patch) | |
tree | b0db34890e7366008754e975a8f28e878c5b28bf /stack.go |
initial
Diffstat (limited to 'stack.go')
-rw-r--r-- | stack.go | 23 |
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] +} |