token

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2025 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package token defines the token types and structures for the Monke programming language.

Tokens are the smallest units of meaning in the language, produced by the lexer during the lexical analysis phase. Each token represents a specific language element such as a keyword, identifier, operator, or delimiter.

Key components:

  • TokenType: A type representing different categories of tokens
  • Token: A structure containing the type and literal value of a token
  • Constants for all token types supported by the language
  • Lookup functions for identifying keywords

This package is used primarily by the lexer to categorize input text and by the parser to understand the structure of the program.

Index

Constants

View Source
const (
	// Single-character tokens
	ILLEGAL = "ILLEGAL"
	EOF     = "EOF"

	// Identifiers & literals
	IDENT  = "IDENT"
	INT    = "INT"
	STRING = "STRING"

	// Operators
	ASSIGN   = "="
	PLUS     = "+"
	MINUS    = "-"
	BANG     = "!"
	ASTERISK = "*"
	SLASH    = "/"
	LT       = "<"
	GT       = ">"
	EQ       = "=="
	NOT_EQ   = "!="

	// Delimiters
	COMMA     = ","
	COLON     = ":"
	SEMICOLON = ";"
	LPAREN    = "("
	RPAREN    = ")"
	LBRACE    = "{"
	RBRACE    = "}"
	LBRACKET  = "["
	RBRACKET  = "]"

	// Keywords
	FUNCTION = "FUNCTION"
	LET      = "LET"
	TRUE     = "TRUE"
	FALSE    = "FALSE"
	IF       = "IF"
	ELSE     = "ELSE"
	RETURN   = "RETURN"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Token

type Token struct {
	Type    Type
	Literal string
}

Token represents a single token in the source code.

type Type

type Type string

Type represents the type of token.

func LookupIdent

func LookupIdent(ident string) Type

LookupIdent checks if the given identifier is a keyword. If it is, it returns the corresponding token type. Otherwise, it returns the IDENT token type.

Jump to

Keyboard shortcuts

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