fleshed out GetVar, added Token stack collection, started printing module
This commit is contained in:
parent
516fda54b3
commit
84013cb4a0
6 changed files with 89 additions and 2 deletions
22
pkg/shsh/stack.go
Normal file
22
pkg/shsh/stack.go
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
package shsh
|
||||
|
||||
type TokenStack struct {
|
||||
buffer []*Token
|
||||
int capacity
|
||||
}
|
||||
|
||||
func (s *Stack) Push(v *Token) {
|
||||
s.capacity++
|
||||
*s.buffer = append(*s.buffer, v)
|
||||
}
|
||||
|
||||
func (s *Stack) Pop() *Token {
|
||||
if s.capacity <= 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
s.capacity--
|
||||
res := *s.buffer[len(*s.buffer) - 1]
|
||||
*s = *s.buffer[ :len(*s) - 1]
|
||||
return ret
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue