Documentation
¶
Index ¶
- Variables
- func Check(program []Stmt, lines [][]rune) error
- func Interpret(program []Stmt, lines [][]rune) error
- func PrintAST(program Stmt) string
- type ASTPrinter
- func (a ASTPrinter) VisitAnonymousFunction(expr *ExprAnonymousFunction) (any, error)
- func (a ASTPrinter) VisitAssign(assign *ExprAssign) (any, error)
- func (a ASTPrinter) VisitBinary(binary *ExprBinary) (any, error)
- func (a ASTPrinter) VisitBlock(stmt *StmtBlock) error
- func (a ASTPrinter) VisitCall(call *ExprCall) (any, error)
- func (a ASTPrinter) VisitExpression(stmt *StmtExpression) error
- func (a ASTPrinter) VisitFor(stmt *StmtFor) error
- func (a ASTPrinter) VisitFuncDecl(stmt *StmtFuncDecl) error
- func (a ASTPrinter) VisitGrouping(grouping *ExprGrouping) (any, error)
- func (a ASTPrinter) VisitIf(stmt *StmtIf) error
- func (a ASTPrinter) VisitList(list *ExprList) (any, error)
- func (a ASTPrinter) VisitLiteral(literal *ExprLiteral) (any, error)
- func (a ASTPrinter) VisitLogical(logical *ExprLogical) (any, error)
- func (a ASTPrinter) VisitLoopControl(stmt *StmtLoopControl) error
- func (a ASTPrinter) VisitReturn(stmt *StmtReturn) error
- func (a ASTPrinter) VisitSubscript(expr *ExprSubscript) (any, error)
- func (a ASTPrinter) VisitTernary(ternary *ExprTernary) (any, error)
- func (a ASTPrinter) VisitThrow(stmt *StmtThrow) error
- func (a ASTPrinter) VisitTry(stmt *StmtTry) error
- func (a ASTPrinter) VisitUnary(unary *ExprUnary) (any, error)
- func (a ASTPrinter) VisitVarDecl(stmt *StmtVarDecl) error
- func (a ASTPrinter) VisitVariable(variable *ExprVariable) (any, error)
- func (a ASTPrinter) VisitWhile(stmt *StmtWhile) error
- type CallError
- type Callable
- type Environment
- type Exception
- type Expr
- type ExprAnonymousFunction
- type ExprAssign
- type ExprBinary
- type ExprCall
- type ExprGrouping
- type ExprList
- type ExprLiteral
- type ExprLogical
- type ExprSubscript
- type ExprTernary
- type ExprUnary
- type ExprVariable
- type ExprVisitor
- type LoopControl
- type ParseError
- type PrinterResult
- type Return
- type RuntimeError
- type ScanError
- type Stmt
- type StmtBlock
- type StmtExpression
- type StmtFor
- type StmtFuncDecl
- type StmtIf
- type StmtLoopControl
- type StmtReturn
- type StmtThrow
- type StmtTry
- type StmtVarDecl
- type StmtVisitor
- type StmtWhile
- type Token
- type TokenType
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrAlreadyDefined = errors.New("The name is already defined in this scope.") ErrUndefined = errors.New("Undefined name.") )
Functions ¶
Types ¶
type ASTPrinter ¶
type ASTPrinter struct{}
func (ASTPrinter) VisitAnonymousFunction ¶
func (a ASTPrinter) VisitAnonymousFunction(expr *ExprAnonymousFunction) (any, error)
func (ASTPrinter) VisitAssign ¶
func (a ASTPrinter) VisitAssign(assign *ExprAssign) (any, error)
func (ASTPrinter) VisitBinary ¶
func (a ASTPrinter) VisitBinary(binary *ExprBinary) (any, error)
func (ASTPrinter) VisitBlock ¶
func (a ASTPrinter) VisitBlock(stmt *StmtBlock) error
func (ASTPrinter) VisitExpression ¶
func (a ASTPrinter) VisitExpression(stmt *StmtExpression) error
func (ASTPrinter) VisitFor ¶
func (a ASTPrinter) VisitFor(stmt *StmtFor) error
func (ASTPrinter) VisitFuncDecl ¶
func (a ASTPrinter) VisitFuncDecl(stmt *StmtFuncDecl) error
func (ASTPrinter) VisitGrouping ¶
func (a ASTPrinter) VisitGrouping(grouping *ExprGrouping) (any, error)
func (ASTPrinter) VisitIf ¶
func (a ASTPrinter) VisitIf(stmt *StmtIf) error
func (ASTPrinter) VisitLiteral ¶
func (a ASTPrinter) VisitLiteral(literal *ExprLiteral) (any, error)
func (ASTPrinter) VisitLogical ¶
func (a ASTPrinter) VisitLogical(logical *ExprLogical) (any, error)
func (ASTPrinter) VisitLoopControl ¶
func (a ASTPrinter) VisitLoopControl(stmt *StmtLoopControl) error
func (ASTPrinter) VisitReturn ¶
func (a ASTPrinter) VisitReturn(stmt *StmtReturn) error
func (ASTPrinter) VisitSubscript ¶
func (a ASTPrinter) VisitSubscript(expr *ExprSubscript) (any, error)
func (ASTPrinter) VisitTernary ¶
func (a ASTPrinter) VisitTernary(ternary *ExprTernary) (any, error)
func (ASTPrinter) VisitThrow ¶
func (a ASTPrinter) VisitThrow(stmt *StmtThrow) error
func (ASTPrinter) VisitTry ¶
func (a ASTPrinter) VisitTry(stmt *StmtTry) error
func (ASTPrinter) VisitUnary ¶
func (a ASTPrinter) VisitUnary(unary *ExprUnary) (any, error)
func (ASTPrinter) VisitVarDecl ¶
func (a ASTPrinter) VisitVarDecl(stmt *StmtVarDecl) error
func (ASTPrinter) VisitVariable ¶
func (a ASTPrinter) VisitVariable(variable *ExprVariable) (any, error)
func (ASTPrinter) VisitWhile ¶
func (a ASTPrinter) VisitWhile(stmt *StmtWhile) error
type Environment ¶
type Environment struct {
// contains filtered or unexported fields
}
func NewEnvironment ¶
func NewEnvironment(parent *Environment) *Environment
func (*Environment) Exists ¶
func (e *Environment) Exists(name string) bool
type Exception ¶
type Expr ¶
type Expr interface {
Accept(visitor ExprVisitor) (any, error)
}
type ExprAnonymousFunction ¶
type ExprAnonymousFunction struct { Keyword Token Body Stmt Parameters []string ReturnValueCount int Throws bool }
func (*ExprAnonymousFunction) Accept ¶
func (e *ExprAnonymousFunction) Accept(visitor ExprVisitor) (any, error)
type ExprAssign ¶
func (*ExprAssign) Accept ¶
func (e *ExprAssign) Accept(visitor ExprVisitor) (any, error)
type ExprBinary ¶
func (*ExprBinary) Accept ¶
func (e *ExprBinary) Accept(visitor ExprVisitor) (any, error)
type ExprGrouping ¶
type ExprGrouping struct {
Expr Expr
}
func (*ExprGrouping) Accept ¶
func (e *ExprGrouping) Accept(visitor ExprVisitor) (any, error)
type ExprLiteral ¶
type ExprLiteral struct {
Value any
}
func (*ExprLiteral) Accept ¶
func (e *ExprLiteral) Accept(visitor ExprVisitor) (any, error)
type ExprLogical ¶
func (*ExprLogical) Accept ¶
func (e *ExprLogical) Accept(visitor ExprVisitor) (any, error)
type ExprSubscript ¶
func (*ExprSubscript) Accept ¶
func (e *ExprSubscript) Accept(visitor ExprVisitor) (any, error)
type ExprTernary ¶
func (*ExprTernary) Accept ¶
func (e *ExprTernary) Accept(visitor ExprVisitor) (any, error)
type ExprVariable ¶
func (*ExprVariable) Accept ¶
func (e *ExprVariable) Accept(visitor ExprVisitor) (any, error)
type ExprVisitor ¶
type ExprVisitor interface { VisitLiteral(expr *ExprLiteral) (any, error) VisitVariable(expr *ExprVariable) (any, error) VisitCall(expr *ExprCall) (any, error) VisitSubscript(expr *ExprSubscript) (any, error) VisitGrouping(expr *ExprGrouping) (any, error) VisitList(expr *ExprList) (any, error) VisitUnary(expr *ExprUnary) (any, error) VisitBinary(expr *ExprBinary) (any, error) VisitLogical(expr *ExprLogical) (any, error) VisitTernary(expr *ExprTernary) (any, error) VisitAssign(expr *ExprAssign) (any, error) VisitAnonymousFunction(expr *ExprAnonymousFunction) (any, error) }
type LoopControl ¶
type LoopControl struct {
Type TokenType
}
func (LoopControl) Error ¶
func (l LoopControl) Error() string
type ParseError ¶
func (ParseError) Error ¶
func (p ParseError) Error() string
type PrinterResult ¶
type PrinterResult string
func (PrinterResult) Error ¶
func (p PrinterResult) Error() string
type RuntimeError ¶
func (RuntimeError) Error ¶
func (r RuntimeError) Error() string
type Stmt ¶
type Stmt interface {
Accept(visitor StmtVisitor) error
}
type StmtBlock ¶
type StmtBlock struct {
Statements []Stmt
}
func (*StmtBlock) Accept ¶
func (s *StmtBlock) Accept(visitor StmtVisitor) error
type StmtExpression ¶
type StmtExpression struct {
Expr Expr
}
func (*StmtExpression) Accept ¶
func (s *StmtExpression) Accept(visitor StmtVisitor) error
type StmtFuncDecl ¶
type StmtFuncDecl struct { Name Token Body Stmt Parameters []string ReturnValueCount int Throws bool }
func (*StmtFuncDecl) Accept ¶
func (s *StmtFuncDecl) Accept(visitor StmtVisitor) error
type StmtLoopControl ¶
type StmtLoopControl struct {
Keyword Token
}
func (*StmtLoopControl) Accept ¶
func (s *StmtLoopControl) Accept(visitor StmtVisitor) error
type StmtReturn ¶
func (*StmtReturn) Accept ¶
func (s *StmtReturn) Accept(visitor StmtVisitor) error
type StmtVarDecl ¶
func (*StmtVarDecl) Accept ¶
func (s *StmtVarDecl) Accept(visitor StmtVisitor) error
type StmtVisitor ¶
type StmtVisitor interface { VisitExpression(stmt *StmtExpression) error VisitBlock(stmt *StmtBlock) error VisitVarDecl(stmt *StmtVarDecl) error VisitFuncDecl(stmt *StmtFuncDecl) error VisitIf(stmt *StmtIf) error VisitWhile(stmt *StmtWhile) error VisitFor(stmt *StmtFor) error VisitLoopControl(stmt *StmtLoopControl) error VisitReturn(stmt *StmtReturn) error VisitThrow(stmt *StmtThrow) error VisitTry(stmt *StmtTry) error }
type TokenType ¶
type TokenType string
const ( PLUS TokenType = "PLUS" PLUS_EQUAL TokenType = "PLUS_EQUAL" PLUS_PLUS TokenType = "PLUS_PLUS" MINUS TokenType = "MINUS" MINUS_EQUAL TokenType = "MINUS_EQUAL" MINUS_MINUS TokenType = "MINUS_MINUS" ASTERISK TokenType = "ASTERISK" ASTERISK_EQUAL TokenType = "ASTERISK_EQUAL" ASTERISK_ASTERISK TokenType = "ASTERISK_ASTERISK" ASTERISK_ASTERISK_EQUAL TokenType = "ASTERISK_ASTERISK_EQUAL" SLASH TokenType = "SLASH" SLASH_EQUAL TokenType = "SLASH_EQUAL" PERCENT TokenType = "PERCENT" PERCENT_EQUAL TokenType = "PERCENT_EQUAL" OPEN_PAREN TokenType = "OPEN_PAREN" CLOSE_PAREN TokenType = "CLOSE_PAREN" OPEN_BRACE TokenType = "OPEN_BRACE" CLOSE_BRACE TokenType = "CLOSE_BRACE" OPEN_BRACKET TokenType = "OPEN_BRACKET" CLOSE_BRACKET TokenType = "CLOSE_BRACKET" EQUAL TokenType = "EQUAL" EQUAL_EQUAL TokenType = "EQUAL_EQUAL" BANG TokenType = "BANG" BANG_EQUAL TokenType = "BANG_EQUAL" LESS TokenType = "LESS" LESS_EQUAL TokenType = "LESS_EQUAL" GREATER TokenType = "GREATER" GREATER_EQUAL TokenType = "GREATER_EQUAL" AND TokenType = "AND" OR TokenType = "OR" XOR TokenType = "XOR" NUMBER TokenType = "NUMBER" STRING TokenType = "STRING" IDENTIFIER TokenType = "IDENTIFIER" SEMICOLON TokenType = "SEMICOLON" COMMA TokenType = "COMMA" QUESTION_MARK TokenType = "QUESTION_MARK" COLON TokenType = "COLON" TRUE TokenType = "TRUE" FALSE TokenType = "FALSE" VAR TokenType = "VAR" FUNC TokenType = "FUNC" IF TokenType = "IF" ELSE TokenType = "ELSE" WHILE TokenType = "WHILE" FOR TokenType = "FOR" BREAK TokenType = "BREAK" CONTINUE TokenType = "CONTINUE" RETURN TokenType = "RETURN" TRY TokenType = "TRY" CATCH TokenType = "CATCH" THROW TokenType = "THROW" THROWS TokenType = "THROWS" EOF TokenType = "EOF" )
Click to show internal directories.
Click to hide internal directories.