lexer

package
v0.0.0-...-1de4a8b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const STEP = "lexing"

Variables

View Source
var Keywords = map[string]TokenType{
	"if":   TTKeywordIf,
	"goto": TTKeywordGoto,
	"call": TTKeywordCall,
}
View Source
var Operators = map[string]TokenType{
	"=":  TTOpAssign,
	"<":  TTOpLt,
	">":  TTOpGt,
	"<=": TTOpLte,
	">=": TTOpGte,
	"==": TTOpEq,
	"!=": TTOpNeq,
	"+":  TTOpAdd,
	"-":  TTOpSub,
	"*":  TTOpMul,
	"/":  TTOpDiv,
	"%":  TTOpMod,
	"^":  TTOpPow,
}

Functions

func IsKeyword

func IsKeyword(word string) bool

Types

type Token

type Token struct {
	Type    TokenType
	Length  int
	Data    string
	Context TokenContext
}

func Lex

func Lex(code, filename string) ([]Token, error)

type TokenContext

type TokenContext struct {
	Line   int
	Column int
	Index  int
	File   string
}

func (*TokenContext) Error

func (ctx *TokenContext) Error(step, message string, tip ...string) error

type TokenType

type TokenType string
const (
	TTKeywordIf       TokenType = "if"
	TTKeywordGoto     TokenType = "goto"
	TTKeywordShownum  TokenType = "shownum"
	TTKeywordShowchar TokenType = "showchar"
	TTKeywordInput    TokenType = "input"
	TTKeywordCall     TokenType = "call"

	TTIdentifier TokenType = "identifier"
	TTLiteralInt TokenType = "literal_int"
	TTLiteralStr TokenType = "literal_str"

	TTOpAssign TokenType = "op_assign"

	TTOpLt  TokenType = "op_lt"
	TTOpGt  TokenType = "op_gt"
	TTOpLte TokenType = "op_lte"
	TTOpGte TokenType = "op_gte"
	TTOpEq  TokenType = "op_eq"
	TTOpNeq TokenType = "op_neq"

	TTOpAdd TokenType = "op_add"
	TTOpSub TokenType = "op_sub"
	TTOpMul TokenType = "op_mul"
	TTOpDiv TokenType = "op_div"
	TTOpMod TokenType = "op_mod"
	TTOpPow TokenType = "op_pow"

	TTLabel TokenType = "label"

	TTEndStmt TokenType = "end_stmt"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL