blob: 0d49e09b4fcc3b1d70e3be72e75042daea1c95e3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
package parser
type nodeStack struct {
top *element
size int
}
type element struct {
value AstNode
next *element
}
func (s *nodeStack) topValue() AstNode {
if s.size == 0 {
return nil
}
return s.top.value
}
// Push pushes a node onto the stack.
func (s *nodeStack) push(value AstNode) {
s.top = &element{value, s.top}
s.size++
}
// Pop removes the node from the stack and returns it.
func (s *nodeStack) pop() (value AstNode) {
if s.size > 0 {
value, s.top = s.top.value, s.top.next
s.size--
return
}
return nil
}
|