aboutsummaryrefslogblamecommitdiff
path: root/stack.go
blob: c0850d4438ae6700f4a2bab0d1ed3a486acb0fc9 (plain) (tree)


























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