interpreter

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package interpreter implement the Interpreter design pattern. It provides a domain-specific language (DSL) for scripting fairytales. The Tokenize function performs lexical analysis, generating an abstract syntax token list. The Parse function interprets these tokens to produce a human-readable representation of the fairytale narrative.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(tokens []Token) string

Parse implements Token parsing functionality to the string.

func Run

func Run()

Types

type Token

type Token struct {
	Type  TokenType
	Actor string
	Value string
}

Token represents the chunk of the abstract syntax tree.

func NewToken

func NewToken(tokenType TokenType, actor string, value string) *Token

NewToken constructs the new Token.

func Tokenize

func Tokenize(fullString string) []Token

Tokenize implements lexing part of the interpreter.

type TokenType

type TokenType byte
const (
	Title TokenType = iota
	Character
	Speak
	Move
	Eat
	Shoot
	Encounter
	End
)

TokenType constant enumerables.

Jump to

Keyboard shortcuts

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