expression/stack.go
Alexander Kiryukhin cc4c01c69c
first commit
2022-07-01 02:16:07 +03:00

27 lines
387 B
Go

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])
}