token

package
v0.0.0-...-c04ea6e Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetKeywordsMapping

func GetKeywordsMapping() map[string]Type

func GetOperatorsMapping

func GetOperatorsMapping() map[string]Type

func HasOperatorPrefix

func HasOperatorPrefix(reading string) bool

Types

type Token

type Token struct {
	TokenType Type
	Raw       string
	Locator   locator.Locator
}

A Token represents a mainingful word in a program.

func EOFToken

func EOFToken(locator locator.Locator) *Token

EOFToken is a factory for generating a default EOF token

func IllegalToken

func IllegalToken(raw string, locator locator.Locator) *Token

IllegalToken is a factory for generating a default illegal token

func MatchKeyword

func MatchKeyword(reading string) *Token

MatchKeyword returns a token containing info about that keyword, or nil if input is not a keyword

func MatchOperator

func MatchOperator(reading string) *Token

func (*Token) GetLocation

func (tok *Token) GetLocation() string

func (*Token) String

func (tok *Token) String() string

type Type

type Type int

Type is the type of a token

const (
	// ILLEGAL is a type of token that is not specified in language spec (should not exist)
	ILLEGAL Type = iota
	EOF
	COMMENT

	LITERAL
	IDENTIFIER

	// consts
	INT_LITERAL
	FLOAT_LITERAL
	CHAR_LITERAL
	BOOLEAN_LITERAL
	STRING_LITERAL

	// operators
	ADD
	SUB
	MUL
	DIV
	MOD
	POW

	INCREMENT
	DECREMENT

	LAND
	LOR
	LNOT

	ASSIGN
	ASSIGN_ADD
	ASSIGN_SUB
	ASSIGN_MUL
	ASSIGN_DIV
	ASSIGN_MOD
	ASSIGN_POW

	EQUAL
	NOT_EQUAL // not equal
	LESS
	LEQ // less or equal
	GREATER
	GEQ              // greater or equal
	TRIPLE_EQUAL     // deep equal
	TRIPLE_NOT_EQUAL // deep not equal

	LEFT_PAREN
	RIGHT_PAREN

	LEFT_CURLY_BRACE
	RIGHT_CURLY_BRACE

	QUESTION_MARK

	SEMI // SEMI: semi-colon (;)
	COLON
	COMMA

	// keywords
	LET
	CONST

	IF
	ELSE

	WHILE
	FOR
	IN
	BREAK

	SWITCH
	CASE
	DEFAULT

	INT_KEYWORD
	FLOAT_KEYWORD
	CHAR_KEYWORD
	BOOL_KEYWORD
	STRING_KEYWORD

	TRUE
	FALSE

	PRINT
)

func (Type) String

func (tokenType Type) String() string

Jump to

Keyboard shortcuts

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