Documentation ¶
Index ¶
- type Assign
- type Binary
- type Block
- type Call
- type CallFunc
- type Callable
- type Class
- type ClassType
- type Environment
- func (e *Environment) Assign(name Token, value interface{})
- func (e *Environment) AssignAt(distance int, name Token, value interface{})
- func (e *Environment) Define(name string, value interface{})
- func (e *Environment) Get(name Token) interface{}
- func (e *Environment) GetAt(distance int, name string) interface{}
- type Expr
- type Expression
- type ExpressionVisitor
- type Function
- type FunctionType
- type Get
- type Grouping
- type If
- type Interpreter
- func (i *Interpreter) Interpret(statements []Stmt) (err error)
- func (i *Interpreter) Resolve(expr Expr, depth int)
- func (i *Interpreter) VisitAssignExpr(expr Assign) interface{}
- func (i *Interpreter) VisitBinaryExpr(expr Binary) interface{}
- func (i *Interpreter) VisitBlockStmt(stmt Block)
- func (i *Interpreter) VisitCallExpr(expr Call) interface{}
- func (i *Interpreter) VisitClassStmt(stmt Class)
- func (i *Interpreter) VisitExpressionStmt(stmt Expression)
- func (i *Interpreter) VisitFunctionStmt(stmt Function)
- func (i *Interpreter) VisitGetExpr(expr Get) interface{}
- func (i *Interpreter) VisitGroupingExpr(expr Grouping) interface{}
- func (i *Interpreter) VisitIfStmt(stmt If)
- func (i *Interpreter) VisitLiteralExpr(expr Literal) interface{}
- func (i *Interpreter) VisitLogicalExpr(expr Logical) interface{}
- func (i *Interpreter) VisitPrintStmt(stmt Print)
- func (i *Interpreter) VisitReturnStmt(stmt Return)
- func (i *Interpreter) VisitSetExpr(expr Set) interface{}
- func (i *Interpreter) VisitSuperExpr(expr *Super) interface{}
- func (i *Interpreter) VisitThisExpr(expr This) interface{}
- func (i *Interpreter) VisitUnaryExpr(expr Unary) interface{}
- func (i *Interpreter) VisitVarStmt(stmt Var)
- func (i *Interpreter) VisitVariableExpr(expr Variable) interface{}
- func (i *Interpreter) VisitWhileStmt(stmt While)
- type Literal
- type Logical
- type LoxClass
- type LoxError
- type LoxFunction
- type LoxInstance
- type Parser
- type Print
- type ProtoCallable
- type Resolver
- func (r *Resolver) ResolveStatements(statements []Stmt) (err error)
- func (r *Resolver) VisitAssignExpr(expr Assign) interface{}
- func (r *Resolver) VisitBinaryExpr(expr Binary) interface{}
- func (r *Resolver) VisitBlockStmt(stmt Block)
- func (r *Resolver) VisitCallExpr(expr Call) interface{}
- func (r *Resolver) VisitClassStmt(stmt Class)
- func (r *Resolver) VisitExpressionStmt(stmt Expression)
- func (r *Resolver) VisitFunctionStmt(stmt Function)
- func (r *Resolver) VisitGetExpr(expr Get) interface{}
- func (r *Resolver) VisitGroupingExpr(expr Grouping) interface{}
- func (r *Resolver) VisitIfStmt(stmt If)
- func (r *Resolver) VisitLiteralExpr(expr Literal) interface{}
- func (r *Resolver) VisitLogicalExpr(expr Logical) interface{}
- func (r *Resolver) VisitPrintStmt(stmt Print)
- func (r *Resolver) VisitReturnStmt(stmt Return)
- func (r *Resolver) VisitSetExpr(expr Set) interface{}
- func (r *Resolver) VisitSuperExpr(expr *Super) interface{}
- func (r *Resolver) VisitThisExpr(expr This) interface{}
- func (r *Resolver) VisitUnaryExpr(expr Unary) interface{}
- func (r *Resolver) VisitVarStmt(stmt Var)
- func (r *Resolver) VisitVariableExpr(expr Variable) interface{}
- func (r *Resolver) VisitWhileStmt(stmt While)
- type Return
- type ReturnWrapper
- type RuntimeError
- type Scanner
- type ScannerError
- type Set
- type StatementVisitor
- type Stmt
- type Super
- type This
- type Token
- type TokenType
- type Unary
- type Var
- type Variable
- type While
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Assign ¶
func (*Assign) Accept ¶
func (a *Assign) Accept(visitor ExpressionVisitor) interface{}
type Binary ¶
func (*Binary) Accept ¶
func (b *Binary) Accept(visitor ExpressionVisitor) interface{}
type Block ¶
type Block struct {
Statements []Stmt
}
func (*Block) Accept ¶
func (b *Block) Accept(visitor StatementVisitor)
type CallFunc ¶
type CallFunc func(interpreter *Interpreter, arguments []interface{}) interface{}
type Callable ¶
type Callable interface { Call(interpreter *Interpreter, arguments []interface{}) interface{} Arity() int }
type Environment ¶
type Environment struct { Values map[string]interface{} // contains filtered or unexported fields }
func NewEnvironment ¶
func NewEnvironment() *Environment
func NewEnvironmentWithEnclosing ¶
func NewEnvironmentWithEnclosing(enclosing *Environment) *Environment
func (*Environment) Assign ¶
func (e *Environment) Assign(name Token, value interface{})
func (*Environment) AssignAt ¶
func (e *Environment) AssignAt(distance int, name Token, value interface{})
func (*Environment) Define ¶
func (e *Environment) Define(name string, value interface{})
func (*Environment) Get ¶
func (e *Environment) Get(name Token) interface{}
func (*Environment) GetAt ¶
func (e *Environment) GetAt(distance int, name string) interface{}
type Expr ¶
type Expr interface {
Accept(visitor ExpressionVisitor) interface{}
}
type Expression ¶
type Expression struct {
Expression Expr
}
func NewExpression ¶
func NewExpression(expr Expr) *Expression
func (*Expression) Accept ¶
func (s *Expression) Accept(visitor StatementVisitor)
type ExpressionVisitor ¶
type ExpressionVisitor interface { VisitBinaryExpr(expr Binary) interface{} VisitCallExpr(expr Call) interface{} VisitGroupingExpr(expr Grouping) interface{} VisitLiteralExpr(expr Literal) interface{} VisitLogicalExpr(expr Logical) interface{} VisitUnaryExpr(expr Unary) interface{} VisitVariableExpr(expr Variable) interface{} VisitAssignExpr(expr Assign) interface{} VisitGetExpr(expr Get) interface{} VisitSetExpr(expr Set) interface{} VisitSuperExpr(expr *Super) interface{} VisitThisExpr(expr This) interface{} }
type FunctionType ¶
type FunctionType int
const ( NONE FunctionType = iota FUNCTION INITIALIZER METHOD )
type Grouping ¶
type Grouping struct {
Expression Expr
}
func NewGrouping ¶
func (*Grouping) Accept ¶
func (g *Grouping) Accept(visitor ExpressionVisitor) interface{}
type Interpreter ¶
type Interpreter struct {
// contains filtered or unexported fields
}
func NewInterpreter ¶
func NewInterpreter() *Interpreter
func (*Interpreter) Interpret ¶
func (i *Interpreter) Interpret(statements []Stmt) (err error)
func (*Interpreter) Resolve ¶
func (i *Interpreter) Resolve(expr Expr, depth int)
func (*Interpreter) VisitAssignExpr ¶
func (i *Interpreter) VisitAssignExpr(expr Assign) interface{}
func (*Interpreter) VisitBinaryExpr ¶
func (i *Interpreter) VisitBinaryExpr(expr Binary) interface{}
func (*Interpreter) VisitBlockStmt ¶
func (i *Interpreter) VisitBlockStmt(stmt Block)
func (*Interpreter) VisitCallExpr ¶
func (i *Interpreter) VisitCallExpr(expr Call) interface{}
func (*Interpreter) VisitClassStmt ¶
func (i *Interpreter) VisitClassStmt(stmt Class)
func (*Interpreter) VisitExpressionStmt ¶
func (i *Interpreter) VisitExpressionStmt(stmt Expression)
func (*Interpreter) VisitFunctionStmt ¶
func (i *Interpreter) VisitFunctionStmt(stmt Function)
func (*Interpreter) VisitGetExpr ¶
func (i *Interpreter) VisitGetExpr(expr Get) interface{}
func (*Interpreter) VisitGroupingExpr ¶
func (i *Interpreter) VisitGroupingExpr(expr Grouping) interface{}
func (*Interpreter) VisitIfStmt ¶
func (i *Interpreter) VisitIfStmt(stmt If)
func (*Interpreter) VisitLiteralExpr ¶
func (i *Interpreter) VisitLiteralExpr(expr Literal) interface{}
func (*Interpreter) VisitLogicalExpr ¶
func (i *Interpreter) VisitLogicalExpr(expr Logical) interface{}
func (*Interpreter) VisitPrintStmt ¶
func (i *Interpreter) VisitPrintStmt(stmt Print)
func (*Interpreter) VisitReturnStmt ¶
func (i *Interpreter) VisitReturnStmt(stmt Return)
func (*Interpreter) VisitSetExpr ¶
func (i *Interpreter) VisitSetExpr(expr Set) interface{}
func (*Interpreter) VisitSuperExpr ¶
func (i *Interpreter) VisitSuperExpr(expr *Super) interface{}
func (*Interpreter) VisitThisExpr ¶
func (i *Interpreter) VisitThisExpr(expr This) interface{}
func (*Interpreter) VisitUnaryExpr ¶
func (i *Interpreter) VisitUnaryExpr(expr Unary) interface{}
func (*Interpreter) VisitVarStmt ¶
func (i *Interpreter) VisitVarStmt(stmt Var)
func (*Interpreter) VisitVariableExpr ¶
func (i *Interpreter) VisitVariableExpr(expr Variable) interface{}
func (*Interpreter) VisitWhileStmt ¶
func (i *Interpreter) VisitWhileStmt(stmt While)
type Literal ¶
type Literal struct {
Value interface{}
}
func NewLiteral ¶
func NewLiteral(value interface{}) *Literal
func (*Literal) Accept ¶
func (l *Literal) Accept(visitor ExpressionVisitor) interface{}
type Logical ¶
func (*Logical) Accept ¶
func (l *Logical) Accept(visitor ExpressionVisitor) interface{}
type LoxClass ¶
type LoxClass struct { Name string Superclass *LoxClass Methods map[string]LoxFunction }
func NewLoxClass ¶
func NewLoxClass(name string, superclass *LoxClass, methods map[string]LoxFunction) *LoxClass
func (*LoxClass) Call ¶
func (c *LoxClass) Call(interpreter *Interpreter, arguments []interface{}) interface{}
func (*LoxClass) FindMethod ¶
func (c *LoxClass) FindMethod(name string) *LoxFunction
type LoxError ¶
func NewLoxError ¶
type LoxFunction ¶
type LoxFunction struct { Declaration Function Closure *Environment // contains filtered or unexported fields }
func NewLoxFunction ¶
func NewLoxFunction(declaration Function, closure *Environment, isInitializer bool) *LoxFunction
func (*LoxFunction) Arity ¶
func (f *LoxFunction) Arity() int
func (*LoxFunction) Bind ¶
func (f *LoxFunction) Bind(instance *LoxInstance) *LoxFunction
func (*LoxFunction) Call ¶
func (f *LoxFunction) Call(interpreter *Interpreter, arguments []interface{}) (retVal interface{})
func (LoxFunction) String ¶
func (f LoxFunction) String() string
type LoxInstance ¶
func NewLoxInstance ¶
func NewLoxInstance(class LoxClass) *LoxInstance
func (*LoxInstance) Get ¶
func (i *LoxInstance) Get(name Token) interface{}
func (*LoxInstance) Set ¶
func (i *LoxInstance) Set(name Token, value interface{})
func (LoxInstance) String ¶
func (i LoxInstance) String() string
type Print ¶
type Print struct {
Expression Expr
}
func (*Print) Accept ¶
func (p *Print) Accept(visitor StatementVisitor)
type ProtoCallable ¶
type ProtoCallable struct {
// contains filtered or unexported fields
}
func NewProtoCallable ¶
func NewProtoCallable(arity int, call CallFunc) *ProtoCallable
func (*ProtoCallable) Arity ¶
func (p *ProtoCallable) Arity() int
func (*ProtoCallable) Call ¶
func (p *ProtoCallable) Call(interpreter *Interpreter, arguments []interface{}) interface{}
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
func NewResolver ¶
func NewResolver(interpreter *Interpreter) *Resolver
func (*Resolver) ResolveStatements ¶
func (*Resolver) VisitAssignExpr ¶
func (*Resolver) VisitBinaryExpr ¶
func (*Resolver) VisitBlockStmt ¶
func (*Resolver) VisitCallExpr ¶
func (*Resolver) VisitClassStmt ¶
func (*Resolver) VisitExpressionStmt ¶
func (r *Resolver) VisitExpressionStmt(stmt Expression)
func (*Resolver) VisitFunctionStmt ¶
func (*Resolver) VisitGetExpr ¶
func (*Resolver) VisitGroupingExpr ¶
func (*Resolver) VisitIfStmt ¶
func (*Resolver) VisitLiteralExpr ¶
func (*Resolver) VisitLogicalExpr ¶
func (*Resolver) VisitPrintStmt ¶
func (*Resolver) VisitReturnStmt ¶
func (*Resolver) VisitSetExpr ¶
func (*Resolver) VisitSuperExpr ¶
func (*Resolver) VisitThisExpr ¶
func (*Resolver) VisitUnaryExpr ¶
func (*Resolver) VisitVarStmt ¶
func (*Resolver) VisitVariableExpr ¶
func (*Resolver) VisitWhileStmt ¶
type ReturnWrapper ¶
type ReturnWrapper struct {
Value interface{}
}
func NewReturnWrapper ¶
func NewReturnWrapper(value interface{}) *ReturnWrapper
type RuntimeError ¶
func NewRuntimeError ¶
func NewRuntimeError(token Token, message string) *RuntimeError
func (*RuntimeError) Error ¶
func (err *RuntimeError) Error() string
type Scanner ¶
type Scanner struct {
// contains filtered or unexported fields
}
func NewScanner ¶
func (*Scanner) ScanTokens ¶
type ScannerError ¶
func NewScannerError ¶
func NewScannerError(line int, where string, error string) *ScannerError
type StatementVisitor ¶
type Stmt ¶
type Stmt interface {
Accept(visitor StatementVisitor)
}
type This ¶
type This struct {
Keyword Token
}
func (*This) Accept ¶
func (t *This) Accept(visitor ExpressionVisitor) interface{}
type TokenType ¶
type TokenType int
const ( // Single-character tokens. LEFT_PAREN TokenType = iota RIGHT_PAREN LEFT_BRACE RIGHT_BRACE COMMA DOT MINUS PLUS SEMICOLON SLASH STAR // One or two character tokens. BANG BANG_EQUAL EQUAL EQUAL_EQUAL GREATER GREATER_EQUAL LESS LESS_EQUAL // Literals. IDENTIFIER STRING NUMBER // Keywords. AND CLASS ELSE FALSE FUN FOR IF NIL OR PRINT RETURN SUPER THIS TRUE VAR WHILE EOF )
type Variable ¶
type Variable struct {
Name Token
}
func NewVariable ¶
func (*Variable) Accept ¶
func (v *Variable) Accept(visitor ExpressionVisitor) interface{}
Click to show internal directories.
Click to hide internal directories.