Documentation ¶
Index ¶
- type ArgsNumMismatch
- type Callable
- type ClassCallable
- type ErrorHandleReturn
- type ErrorOpNumMismatch
- type FunctionCallable
- type Instance
- type InterpretationError
- type Interpreter
- func (inter *Interpreter) Interpret(stmts []statements.Statement) error
- func (inter *Interpreter) Resolve(expr expressions.Experssion, level int)
- func (inter *Interpreter) VisitAssgin(expr expressions.Assgin) (interface{}, error)
- func (inter *Interpreter) VisitBinary(expr expressions.Binary) (interface{}, error)
- func (inter *Interpreter) VisitBlockStmt(stmt statements.BlockStatement) error
- func (inter *Interpreter) VisitCall(expr expressions.Call) (interface{}, error)
- func (inter *Interpreter) VisitClassStmt(stmt statements.ClassStatement) error
- func (inter *Interpreter) VisitExprStmt(stmt statements.ExperssionStatement) error
- func (inter *Interpreter) VisitFunctionStmt(stmt statements.FunctionStatement) error
- func (inter *Interpreter) VisitGrouping(expr expressions.Grouping) (interface{}, error)
- func (inter *Interpreter) VisitIfStmt(stmt statements.IfStatement) error
- func (inter *Interpreter) VisitLiteral(expr expressions.Literal) (interface{}, error)
- func (inter *Interpreter) VisitLogical(expr expressions.Logical) (interface{}, error)
- func (inter *Interpreter) VisitPrintStmt(stmt statements.PrintStatement) error
- func (inter *Interpreter) VisitPropertyAccess(expr expressions.PropertyAccess) (interface{}, error)
- func (inter *Interpreter) VisitPropertyAssignment(expr expressions.PropertyAssignment) (interface{}, error)
- func (inter *Interpreter) VisitReturnStmt(stmt statements.ReturnStatement) error
- func (inter *Interpreter) VisitSuper(expr expressions.Super) (interface{}, error)
- func (inter *Interpreter) VisitThis(expr expressions.This) (interface{}, error)
- func (inter *Interpreter) VisitUnary(expr expressions.Unary) (interface{}, error)
- func (inter *Interpreter) VisitVairable(expr expressions.Variable) (interface{}, error)
- func (inter *Interpreter) VisitVarDecStmt(stmt statements.VarDecStatement) error
- func (inter *Interpreter) VisitWhileStmt(stmt statements.WhileStatement) error
- type InvalidFieldAssignment
- type InvalidPropertyAccess
- type InvalidSuperclass
- type Locals
- type ObjNotCallable
- type UndefinedProperty
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ArgsNumMismatch ¶
type ArgsNumMismatch struct {
InterpretationError
}
type Callable ¶
type Callable interface { Call(*Interpreter, []interface{}) (interface{}, error) ArgsNum() int }
type ClassCallable ¶
type ClassCallable struct {
// contains filtered or unexported fields
}
func (*ClassCallable) ArgsNum ¶
func (c *ClassCallable) ArgsNum() int
the number of arguments of class is the same as the number of arguments on the initializer
func (*ClassCallable) Call ¶
func (c *ClassCallable) Call(inter *Interpreter, args []interface{}) (interface{}, error)
func (*ClassCallable) String ¶
func (c *ClassCallable) String() string
type ErrorHandleReturn ¶
type ErrorHandleReturn struct {
// contains filtered or unexported fields
}
error to handle unwind for return statement
func (ErrorHandleReturn) Error ¶
func (e ErrorHandleReturn) Error() string
type ErrorOpNumMismatch ¶
type ErrorOpNumMismatch struct {
InterpretationError
}
type FunctionCallable ¶
type FunctionCallable struct { Declaration statements.FunctionStatement Closure *environment.Environment // flags the current function is an initializer IsInit bool }
func (*FunctionCallable) ArgsNum ¶
func (f *FunctionCallable) ArgsNum() int
func (*FunctionCallable) Call ¶
func (f *FunctionCallable) Call(inter *Interpreter, args []interface{}) (interface{}, error)
implementing the callable interface
func (*FunctionCallable) String ¶
func (f *FunctionCallable) String() string
type Instance ¶
type Instance struct {
// contains filtered or unexported fields
}
func (*Instance) Get ¶
func (i *Instance) Get(name expressions.Token) (interface{}, error)
lookup a property on an instance
func (*Instance) Set ¶
func (i *Instance) Set(name expressions.Token, value interface{})
set a field on an instance creation of new field freely is allowed
type InterpretationError ¶
type InterpretationError struct {
// contains filtered or unexported fields
}
Runtime errors
func (*InterpretationError) Error ¶
func (e *InterpretationError) Error() string
implementing the error interface
type Interpreter ¶
type Interpreter struct {
// contains filtered or unexported fields
}
implement expression visitor and statement visitor interface
func New ¶
func New() *Interpreter
func (*Interpreter) Interpret ¶
func (inter *Interpreter) Interpret(stmts []statements.Statement) error
func (*Interpreter) Resolve ¶
func (inter *Interpreter) Resolve(expr expressions.Experssion, level int)
Append new variable resolution (used by the resolver)
func (*Interpreter) VisitAssgin ¶
func (inter *Interpreter) VisitAssgin(expr expressions.Assgin) (interface{}, error)
evaluates the r-value. then stores it in the named variable
func (*Interpreter) VisitBinary ¶
func (inter *Interpreter) VisitBinary(expr expressions.Binary) (interface{}, error)
func (*Interpreter) VisitBlockStmt ¶
func (inter *Interpreter) VisitBlockStmt(stmt statements.BlockStatement) error
func (*Interpreter) VisitCall ¶
func (inter *Interpreter) VisitCall(expr expressions.Call) (interface{}, error)
func (*Interpreter) VisitClassStmt ¶
func (inter *Interpreter) VisitClassStmt(stmt statements.ClassStatement) error
func (*Interpreter) VisitExprStmt ¶
func (inter *Interpreter) VisitExprStmt(stmt statements.ExperssionStatement) error
func (*Interpreter) VisitFunctionStmt ¶
func (inter *Interpreter) VisitFunctionStmt(stmt statements.FunctionStatement) error
convert function parse time representation to its runtime representation
func (*Interpreter) VisitGrouping ¶
func (inter *Interpreter) VisitGrouping(expr expressions.Grouping) (interface{}, error)
grouping node has a reference to an inner node for the expression contained inside the parentheses. recursively evaluate that subexpression and return it.
func (*Interpreter) VisitIfStmt ¶
func (inter *Interpreter) VisitIfStmt(stmt statements.IfStatement) error
evaluates the condition. If truthy, executes the then branch. Otherwise, if there is an else branch, execute that.
func (*Interpreter) VisitLiteral ¶
func (inter *Interpreter) VisitLiteral(expr expressions.Literal) (interface{}, error)
the runtime value was produced during scanning and it in the token. The parser took the value and stuck it in the literal tree node, so to evaluate a literal pull it back out.
func (*Interpreter) VisitLogical ¶
func (inter *Interpreter) VisitLogical(expr expressions.Logical) (interface{}, error)
func (*Interpreter) VisitPrintStmt ¶
func (inter *Interpreter) VisitPrintStmt(stmt statements.PrintStatement) error
func (*Interpreter) VisitPropertyAccess ¶
func (inter *Interpreter) VisitPropertyAccess(expr expressions.PropertyAccess) (interface{}, error)
func (*Interpreter) VisitPropertyAssignment ¶
func (inter *Interpreter) VisitPropertyAssignment(expr expressions.PropertyAssignment) (interface{}, error)
func (*Interpreter) VisitReturnStmt ¶
func (inter *Interpreter) VisitReturnStmt(stmt statements.ReturnStatement) error
func (*Interpreter) VisitSuper ¶
func (inter *Interpreter) VisitSuper(expr expressions.Super) (interface{}, error)
func (*Interpreter) VisitThis ¶
func (inter *Interpreter) VisitThis(expr expressions.This) (interface{}, error)
since to bound to the method it's the same as interpreting variables expression
func (*Interpreter) VisitUnary ¶
func (inter *Interpreter) VisitUnary(expr expressions.Unary) (interface{}, error)
evaluate the operand expression. Then apply the unary operator itself to the result of that. There are two different unary expressions, identified by the type of the operator token.
func (*Interpreter) VisitVairable ¶
func (inter *Interpreter) VisitVairable(expr expressions.Variable) (interface{}, error)
func (*Interpreter) VisitVarDecStmt ¶
func (inter *Interpreter) VisitVarDecStmt(stmt statements.VarDecStatement) error
evaluate the initializer of exists vairable decleration without initializer is allowed
func (*Interpreter) VisitWhileStmt ¶
func (inter *Interpreter) VisitWhileStmt(stmt statements.WhileStatement) error
evaluated the condition . while it's truthy execute the body
type InvalidFieldAssignment ¶
type InvalidFieldAssignment struct {
InterpretationError
}
type InvalidPropertyAccess ¶
type InvalidPropertyAccess struct {
InterpretationError
}
type InvalidSuperclass ¶
type InvalidSuperclass struct {
InterpretationError
}
type Locals ¶
type Locals map[expressions.Experssion]*int
type ObjNotCallable ¶
type ObjNotCallable struct {
InterpretationError
}
type UndefinedProperty ¶
type UndefinedProperty struct {
InterpretationError
}