Skip to content

Commit

Permalink
Introduce token index
Browse files Browse the repository at this point in the history
  • Loading branch information
DQNEO committed Aug 29, 2019
1 parent 0b8462d commit ec66c37
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,24 @@ func tokenize() []*Token {
}

var tokens []*Token
var tokenIndex int = 0

func getToken() *Token {
if tokenIndex == len(tokens) {
return nil
}
token := tokens[tokenIndex]
tokenIndex++
return token
}

type Expr struct {
kind string // "intliteral"
intval int // for intliteral
}

func parse() *Expr {
token := tokens[0]
token := getToken()

intval, _ := strconv.Atoi(token.value)
expr := &Expr{
Expand Down

0 comments on commit ec66c37

Please sign in to comment.