Tiny Interpreter Part 1 of 3

Tiny Interpreter:
Reading Characters

This is the first part of a short series. Posts in a series show their position under the title, and a series menu after the text.

Tokens

A scanner reads characters and groups them into tokens:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
type Token struct {
	Kind  Kind
	Text  string
	Line  int
}

func (s *Scanner) Next() Token {
	s.skipSpace()
	switch c := s.peek(); {
	case isDigit(c):
		return s.number()
	case isLetter(c):
		return s.identifier()
	default:
		return s.symbol()
	}
}

What comes next

The next part turns the tokens into a tree.