This repository has been archived on 2026-05-13. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
sfdl/scanner/token.go
2025-12-03 09:57:17 +08:00

67 lines
1.3 KiB
Go

package scanner
import "math"
type TokenType int
const (
// reserved word
ORIGIN TokenType = iota
ROT
SCALE
IS
FOR
FROM
TO
STEP
DRAW
COLOR
// parameter
T
// sparator
SEMICO
L_BRACKET
R_BRACKET
COMMA
// operator
PLUS
MINUS
MUL
DIV
POWER
// other
FUNC
CONST_ID
NONTOKEN
ERRTOKEN
)
type Token struct {
Type TokenType
Lexeme string
Value float64
Func func(float64) float64
}
var keywords = map[string]Token{
"ORIGIN": {Type: ORIGIN, Lexeme: "ORIGIN"},
"ROT": {Type: ROT, Lexeme: "ROT"},
"SCALE": {Type: SCALE, Lexeme: "SCALE"},
"IS": {Type: IS, Lexeme: "IS"},
"FOR": {Type: FOR, Lexeme: "FOR"},
"FROM": {Type: FROM, Lexeme: "FROM"},
"TO": {Type: TO, Lexeme: "TO"},
"STEP": {Type: STEP, Lexeme: "STEP"},
"DRAW": {Type: DRAW, Lexeme: "DRAW"},
"COLOR": {Type: COLOR, Lexeme: "COLOR"},
"T": {Type: T, Lexeme: "T"},
"PI": {Type: CONST_ID, Lexeme: "PI", Value: math.Pi},
"E": {Type: CONST_ID, Lexeme: "E", Value: math.E},
"SIN": {Type: FUNC, Lexeme: "SIN", Func: math.Sin},
"COS": {Type: FUNC, Lexeme: "COS", Func: math.Cos},
"TAN": {Type: FUNC, Lexeme: "TAN", Func: math.Tan},
"LN": {Type: FUNC, Lexeme: "LN", Func: math.Log},
"EXP": {Type: FUNC, Lexeme: "EXP", Func: math.Exp},
"SQRT": {Type: FUNC, Lexeme: "SQRT", Func: math.Sqrt},
}