interpreter

package
v0.0.0-...-e9dc133 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RETURN   ControlType = "RETURN"
	BREAK                = "BREAK"
	CONTINUE             = "CONTINUE"
)

Variables

View Source
var LoxBreak = &LoxControl{controlType: BREAK}
View Source
var LoxContinue = &LoxControl{controlType: CONTINUE}
View Source
var Natives = []LoxNative{
	&Clock{},
	&Print{},
	&String{},
	&Length{},
	&Map{},
	&Filter{},
	&Reduce{},
	&HasKey{},
	&Size{},
	&Values{},
	&Keys{},
}

Functions

func Hash

func Hash(v string) int

func PrintRepresentation

func PrintRepresentation(v any) string

func Representation

func Representation(v any) string

Types

type Clock

type Clock struct{}

func (Clock) Arity

func (Clock) Arity() int

func (Clock) Call

func (Clock) Call(interpreter *Interpreter, arguments []any) (any, error)

func (Clock) Name

func (Clock) Name() string

type ControlType

type ControlType string

type Environment

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

func NewEnclosingEnvironment

func NewEnclosingEnvironment(enclosing *Environment) *Environment

func NewEnvironment

func NewEnvironment() *Environment

type Filter

type Filter struct{}

func (Filter) Arity

func (Filter) Arity() int

func (Filter) Call

func (Filter) Call(interpreter *Interpreter, arguments []any) (any, error)

func (Filter) Name

func (Filter) Name() string

type HasKey

type HasKey struct{}

func (HasKey) Arity

func (HasKey) Arity() int

func (HasKey) Call

func (HasKey) Call(interpreter *Interpreter, arguments []any) (any, error)

func (HasKey) Name

func (HasKey) Name() string

type Interpreter

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

func NewInterpreter

func NewInterpreter(errors *lox_error.LoxErrors) *Interpreter

func (*Interpreter) Interpret

func (i *Interpreter) Interpret(statements []ast.Statement) (value any, ok bool)

func (*Interpreter) Resolve

func (i *Interpreter) Resolve(expression ast.Expression, depth int)

func (*Interpreter) VisitArrayExpression

func (i *Interpreter) VisitArrayExpression(e *ast.ArrayExpression) any

func (*Interpreter) VisitAssignmentExpression

func (i *Interpreter) VisitAssignmentExpression(e *ast.AssignmentExpression) any

func (*Interpreter) VisitBinaryExpression

func (i *Interpreter) VisitBinaryExpression(be *ast.BinaryExpression) any

func (*Interpreter) VisitBlockStatement

func (i *Interpreter) VisitBlockStatement(s *ast.BlockStatement)

func (*Interpreter) VisitBreakStatement

func (i *Interpreter) VisitBreakStatement(s *ast.BreakStatement)

func (*Interpreter) VisitCallExpression

func (i *Interpreter) VisitCallExpression(e *ast.CallExpression) any

func (*Interpreter) VisitClassStatement

func (i *Interpreter) VisitClassStatement(s *ast.ClassStatement)

func (*Interpreter) VisitContinueStatement

func (i *Interpreter) VisitContinueStatement(s *ast.ContinueStatement)

func (*Interpreter) VisitExpressionStatement

func (i *Interpreter) VisitExpressionStatement(s *ast.ExpressionStatement)

func (*Interpreter) VisitForEachStatement

func (i *Interpreter) VisitForEachStatement(s *ast.ForEachStatement)

func (*Interpreter) VisitFunctionStatement

func (i *Interpreter) VisitFunctionStatement(s *ast.FunctionStatement)

func (*Interpreter) VisitGetExpression

func (i *Interpreter) VisitGetExpression(e *ast.GetExpression) any

func (*Interpreter) VisitGroupedExpression

func (i *Interpreter) VisitGroupedExpression(ge *ast.GroupingExpression) any

func (*Interpreter) VisitIfStatement

func (i *Interpreter) VisitIfStatement(s *ast.IfStatement)

func (*Interpreter) VisitIndexExpression

func (i *Interpreter) VisitIndexExpression(e *ast.IndexExpression) any

func (*Interpreter) VisitIndexedAssignmentExpression

func (i *Interpreter) VisitIndexedAssignmentExpression(e *ast.IndexedAssignmentExpression) any

func (*Interpreter) VisitLambdaExpression

func (i *Interpreter) VisitLambdaExpression(e *ast.LambdaExpression) any

func (*Interpreter) VisitLiteralExpression

func (*Interpreter) VisitLiteralExpression(le *ast.LiteralExpression) any

func (*Interpreter) VisitLogicalExpression

func (i *Interpreter) VisitLogicalExpression(le *ast.LogicalExpression) any

func (*Interpreter) VisitLoopStatement

func (i *Interpreter) VisitLoopStatement(s *ast.LoopStatement)

func (*Interpreter) VisitMapExpression

func (i *Interpreter) VisitMapExpression(e *ast.MapExpression) any

func (*Interpreter) VisitReturnStatement

func (i *Interpreter) VisitReturnStatement(s *ast.ReturnStatement)

func (*Interpreter) VisitSequenceExpression

func (i *Interpreter) VisitSequenceExpression(e *ast.SequenceExpression) any

func (*Interpreter) VisitSetExpression

func (i *Interpreter) VisitSetExpression(e *ast.SetExpression) any

func (*Interpreter) VisitSuperGetExpression

func (i *Interpreter) VisitSuperGetExpression(e *ast.SuperGetExpression) any

func (*Interpreter) VisitSuperSetExpression

func (i *Interpreter) VisitSuperSetExpression(e *ast.SuperSetExpression) any

func (*Interpreter) VisitTernaryExpression

func (i *Interpreter) VisitTernaryExpression(e *ast.TernaryExpression) any

func (*Interpreter) VisitThisExpression

func (i *Interpreter) VisitThisExpression(e *ast.ThisExpression) any

func (*Interpreter) VisitUnaryExpression

func (i *Interpreter) VisitUnaryExpression(ue *ast.UnaryExpression) any

func (*Interpreter) VisitVarStatement

func (i *Interpreter) VisitVarStatement(s *ast.VarStatement)

func (*Interpreter) VisitVariableExpression

func (i *Interpreter) VisitVariableExpression(e *ast.VariableExpression) any

type Keys

type Keys struct{}

func (Keys) Arity

func (Keys) Arity() int

func (Keys) Call

func (Keys) Call(interpreter *Interpreter, arguments []any) (any, error)

func (Keys) Name

func (Keys) Name() string

type Length

type Length struct{}

func (Length) Arity

func (Length) Arity() int

func (Length) Call

func (Length) Call(interpreter *Interpreter, arguments []any) (any, error)

func (Length) Name

func (Length) Name() string

type LoxArray

type LoxArray []any

type LoxCallable

type LoxCallable interface {
	Arity() int
	Call(interpreter *Interpreter, arguments []any) (any, error)
}

type LoxClass

type LoxClass struct {
	Name    string
	Methods map[string]*LoxFunction
	Super   *LoxClass
}

func (LoxClass) Arity

func (c LoxClass) Arity() int

func (*LoxClass) Call

func (c *LoxClass) Call(interpreter *Interpreter, arguments []any) (any, error)

type LoxControl

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

func LoxReturn

func LoxReturn(value any) *LoxControl

type LoxFunction

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

func (LoxFunction) Arity

func (f LoxFunction) Arity() int

func (*LoxFunction) Call

func (f *LoxFunction) Call(interpreter *Interpreter, arguments []any) (returnValue any, err error)

type LoxInstance

type LoxInstance struct {
	Class  *LoxClass
	Fields map[string]any
}

func NewLoxInstance

func NewLoxInstance(class *LoxClass) *LoxInstance

type LoxMap

type LoxMap map[int]MapPair

type LoxNative

type LoxNative interface {
	LoxCallable
	Name() string
}

type LoxObject

type LoxObject interface {
	// contains filtered or unexported methods
}

type Map

type Map struct{}

func (Map) Arity

func (Map) Arity() int

func (Map) Call

func (Map) Call(interpreter *Interpreter, arguments []any) (any, error)

func (Map) Name

func (Map) Name() string

type MapPair

type MapPair struct {
	Key   string
	Value any
}

type Print

type Print struct{}

func (Print) Arity

func (Print) Arity() int

func (Print) Call

func (Print) Call(interpreter *Interpreter, arguments []any) (any, error)

func (Print) Name

func (Print) Name() string

type Reduce

type Reduce struct{}

func (Reduce) Arity

func (Reduce) Arity() int

func (Reduce) Call

func (Reduce) Call(interpreter *Interpreter, arguments []any) (any, error)

func (Reduce) Name

func (Reduce) Name() string

type Size

type Size struct{}

func (Size) Arity

func (Size) Arity() int

func (Size) Call

func (Size) Call(interpreter *Interpreter, arguments []any) (any, error)

func (Size) Name

func (Size) Name() string

type String

type String struct{}

func (String) Arity

func (String) Arity() int

func (String) Call

func (String) Call(interpreter *Interpreter, arguments []any) (any, error)

func (String) Name

func (String) Name() string

type Values

type Values struct{}

func (Values) Arity

func (Values) Arity() int

func (Values) Call

func (Values) Call(interpreter *Interpreter, arguments []any) (any, error)

func (Values) Name

func (Values) Name() string

Jump to

Keyboard shortcuts

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