lexer

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TYPE_INT           = iota
	TYPE_PLUS          // "+"
	TYPE_SUB           // "-"
	TYPE_MUL           // "*"
	TYPE_DIV           // "/"
	TYPE_LP            // "("
	TYPE_RP            // ")"
	TYPE_ASSIGN        // "="
	TYPE_RES_VAR       // "var"
	TYPE_RES_INT       // "int"
	TYPE_NL            // "\n"
	TYPE_VAR           // "([a-z]|[A-Z])([a-z]|[A-Z]|[0-9])*"
	TYPE_FLOAT         // 小数,x.y这种
	TYPE_RES_FLOAT     // "float"
	TYPE_RES_FUNC      // "func"
	TYPE_LB            // "{"
	TYPE_RB            // "}"
	TYPE_COMMA         // ","
	TYPE_RES_RET       // "return"
	TYPE_RES_VOID      // "void"
	TYPE_RES_TRUE      // "true"
	TYPE_RES_FALSE     // "false"
	TYPE_AND           // "&&"
	TYPE_OR            // "||"
	TYPE_EQ            // "=="
	TYPE_RES_BOOL      // "bool"
	TYPE_LG            // ">"
	TYPE_SM            // "<"
	TYPE_LEQ           // ">="
	TYPE_SEQ           // "<="
	TYPE_NOT           // "!"
	TYPE_NEQ           // "!="
	TYPE_RES_IF        // "if"
	TYPE_RES_EL        // "else"
	TYPE_DEAS          // ":="
	TYPE_RES_FOR       // "for"
	TYPE_SEMI          // ";"
	TYPE_RES_BR        // "break"
	TYPE_RES_CO        // "continue"
	TYPE_RES_TYPE      // "type"
	TYPE_RES_STRUCT    // "struct"
	TYPE_COLON         // ":"
	TYPE_LSB           // "["
	TYPE_RSB           // "]"
	TYPE_ESP           // "&"
	TYPE_RES_INT32     // "int32"
	TYPE_RES_FLOAT32   // "float32"
	TYPE_RES_INT64     // "int64"
	TYPE_RES_FLOAT64   // "float64"
	TYPE_RES_BYTE      // "byte"
	TYPE_DOT           // "."
	TYPE_RES_THIS      // "this"
	TYPE_RES_INTERFACE // "interface"
	TYPE_RES_NIL       // "nil"
	TYPE_RES_PKG       // "pkg"
	TYPE_STR           // a quoted string
	TYPE_RES_STR       // "string"
	TYPE_RES_IMPORT    // "import"
	TYPE_RES_OP        // "op"
	TYPE_PS            // "%"
	TYPE_SHL           // "<<" 逻辑左移
	TYPE_SHR           // "<<" 算术右移
	TYPE_BIT_OR        // "|"
	TYPE_BIT_XOR       // "^"
	TYPE_RES_YIELD     // "yield"
	TYPE_RES_ASYNC     // "async"
	TYPE_RES_AWAIT     // "await"
)

Variables

View Source
var (
	ErrEOS  = fmt.Errorf("eos error")
	ErrTYPE = fmt.Errorf("the next token doesn't match the expected type")
)

Functions

func DefaultFloatType

func DefaultFloatType() *types.FloatType

func DefaultIntType

func DefaultIntType() *types.IntType

func IsResType

func IsResType(token string) (code int, ok bool)

Types

type Checkpoint

type Checkpoint struct {
	// contains filtered or unexported fields
}

type Lexer

type Lexer struct {
	// contains filtered or unexported fields
}

func (*Lexer) GetPos

func (l *Lexer) GetPos() int

func (*Lexer) GobackTo

func (l *Lexer) GobackTo(c Checkpoint)

func (*Lexer) Peek

func (l *Lexer) Peek() (ch rune, end bool)

func (*Lexer) PeekToken

func (l *Lexer) PeekToken() (code int, token string, eos bool)

func (*Lexer) PrintCurrent

func (l *Lexer) PrintCurrent()

func (*Lexer) Scan

func (l *Lexer) Scan() (code int, token string, eos bool)

func (*Lexer) ScanType

func (l *Lexer) ScanType(code int) (token string, err error)

func (*Lexer) SetCheckpoint

func (l *Lexer) SetCheckpoint() Checkpoint

func (*Lexer) SetInput

func (l *Lexer) SetInput(s string)

Jump to

Keyboard shortcuts

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