lexer

package
v0.0.0-...-c85daa3 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetermineStringType

func DetermineStringType(str string) string

DetermineStringType will determine the type of a given string

func GetPrec

func GetPrec(operator string) int

GetPrec is a simple wrapper for GetOperatorAttributes but only returns the precedance

func IsLitteral

func IsLitteral(token Token) bool

IsLitteral checks if a given token is a litteral type

func ThrowSemanticError

func ThrowSemanticError(token *Token, expected []string, filename string)

ThrowSemanticError can be used when an error occurs while generating an AST and not at interpret time

Types

type Lexer

type Lexer struct {
	Tokens []Token

	FileName, Program string
	// contains filtered or unexported fields
}

Lexer contains all the info needed for the lexer to generate a set of usable tokens

func NewLexer

func NewLexer(filename string, program string) *Lexer

NewLexer creates a new instance of a lexer stuct

func (*Lexer) Lex

func (l *Lexer) Lex()

Lex takes a sourcecode string and transforms it into usable tokens to build an AST with

type OperatorAttributes

type OperatorAttributes struct {
	Precedance    int
	Associativity string
}

OperatorAttributes wraps the precedance and Associativity of a operator

func GetOperatorAttributes

func GetOperatorAttributes(operator string) OperatorAttributes

GetOperatorAttributes returns the precedance and associativity of an operator

type Token

type Token struct {
	Value, Type string
	Line, Col   int
}

Token contains all info about a specific token from syntax

func (Token) HasHigherPrec

func (lhs Token) HasHigherPrec(rhs Token) bool

HasHigherPrec is a simple check for checking if lhs has a bigger precednce than rhs

Jump to

Keyboard shortcuts

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