Documentation ¶
Index ¶
- Constants
- Variables
- type ARType
- type ActivationRecord
- type Assign
- type Ast
- type BinOp
- type Block
- type Boolean
- type BuiltinTypeSymbol
- type CallFunc
- type CallStack
- type Compound
- type Dict
- type Error
- type ErrorCode
- type ErrorType
- type FunctionCall
- type FunctionDecl
- type FunctionRef
- type FunctionSymbol
- type If
- type Interpreter
- func (i *Interpreter) Interpret() (float64, error)
- func (i *Interpreter) Stdout() string
- func (i *Interpreter) Visit(node Ast) interface{}
- func (i *Interpreter) VisitAssign(node *Assign) float64
- func (i *Interpreter) VisitBinOp(node *BinOp) float64
- func (i *Interpreter) VisitBlock(node *Block) float64
- func (i *Interpreter) VisitBoolean(node *Boolean) bool
- func (i *Interpreter) VisitCompound(node *Compound) float64
- func (i *Interpreter) VisitDict(node *Dict) map[string]interface{}
- func (i *Interpreter) VisitFunctionCall(node *FunctionCall) interface{}
- func (i *Interpreter) VisitFunctionDecl(node *FunctionDecl) float64
- func (i *Interpreter) VisitFunctionRef(node *FunctionRef) *FunctionRef
- func (i *Interpreter) VisitIf(node *If) interface{}
- func (i *Interpreter) VisitList(node *List) []interface{}
- func (i *Interpreter) VisitLogical(node *Logical) bool
- func (i *Interpreter) VisitMessage(node *Message) interface{}
- func (i *Interpreter) VisitNoOp(node *NoOp) float64
- func (i *Interpreter) VisitNumber(node *Number) float64
- func (i *Interpreter) VisitPackage(node *Package) float64
- func (i *Interpreter) VisitPrint(node *Print) interface{}
- func (i *Interpreter) VisitProgram(node *Program) float64
- func (i *Interpreter) VisitReturn(node *Return) interface{}
- func (i *Interpreter) VisitString(node *String) string
- func (i *Interpreter) VisitType(node *Type) float64
- func (i *Interpreter) VisitUnaryOp(node *UnaryOp) float64
- func (i *Interpreter) VisitVar(node *Var) interface{}
- func (i *Interpreter) VisitVarDecl(node *VarDecl) float64
- func (i *Interpreter) VisitWhile(node *While) float64
- type Lexer
- func (l *Lexer) Advance()
- func (l *Lexer) GetNextToken() (*Token, error)
- func (l *Lexer) Id() (*Token, error)
- func (l *Lexer) Message() (*Token, error)
- func (l *Lexer) Number() (*Token, error)
- func (l *Lexer) Peek() rune
- func (l *Lexer) SkipComment()
- func (l *Lexer) SkipWhitespace()
- func (l *Lexer) String() (*Token, error)
- type List
- type Logical
- type Message
- type NoOp
- type Number
- type Package
- type Param
- type Parser
- func (p *Parser) AssignmentStatement() (Ast, error)
- func (p *Parser) Block() (Ast, error)
- func (p *Parser) Comparison() (Ast, error)
- func (p *Parser) CompoundStatement() (Ast, error)
- func (p *Parser) Declarations() ([][]Ast, error)
- func (p *Parser) Dict() (Ast, error)
- func (p *Parser) Eat(tokenType TokenType) (err error)
- func (p *Parser) Empty() (Ast, error)
- func (p *Parser) Equality() (Ast, error)
- func (p *Parser) Expr() (Ast, error)
- func (p *Parser) Expression() (Ast, error)
- func (p *Parser) Factor() (Ast, error)
- func (p *Parser) FormalParameterList() ([]Ast, error)
- func (p *Parser) FormalParameters() ([]Ast, error)
- func (p *Parser) FunctionCallStatement() (Ast, error)
- func (p *Parser) FunctionDeclaration() (Ast, error)
- func (p *Parser) FunctionReference() (Ast, error)
- func (p *Parser) IfStatement() (Ast, error)
- func (p *Parser) List() (Ast, error)
- func (p *Parser) LogicAnd() (Ast, error)
- func (p *Parser) LogicOr() (Ast, error)
- func (p *Parser) Package() ([]Ast, error)
- func (p *Parser) Parse() (Ast, error)
- func (p *Parser) PrintStatement() (Ast, error)
- func (p *Parser) Program() (Ast, error)
- func (p *Parser) ReturnStatement() (Ast, error)
- func (p *Parser) Statement() (Ast, error)
- func (p *Parser) StatementList() ([]Ast, error)
- func (p *Parser) Term() (Ast, error)
- func (p *Parser) TypeSpec() (Ast, error)
- func (p *Parser) Variable() (Ast, error)
- func (p *Parser) VariableDeclaration() ([]Ast, error)
- func (p *Parser) WhileStatement() (Ast, error)
- type Print
- type Program
- type Return
- type ScopedSymbolTable
- type SemanticAnalyzer
- func (b *SemanticAnalyzer) Visit(node Ast)
- func (b *SemanticAnalyzer) VisitAssign(node *Assign)
- func (b *SemanticAnalyzer) VisitBinOp(node *BinOp)
- func (b *SemanticAnalyzer) VisitBlock(node *Block)
- func (b *SemanticAnalyzer) VisitBoolean(node *Boolean)
- func (b *SemanticAnalyzer) VisitCompound(node *Compound)
- func (b *SemanticAnalyzer) VisitDict(node *Dict)
- func (b *SemanticAnalyzer) VisitFunctionCall(node *FunctionCall)
- func (b *SemanticAnalyzer) VisitFunctionDecl(node *FunctionDecl)
- func (b *SemanticAnalyzer) VisitFunctionRef(node *FunctionRef)
- func (b *SemanticAnalyzer) VisitIf(node *If)
- func (b *SemanticAnalyzer) VisitList(node *List)
- func (b *SemanticAnalyzer) VisitLogical(node *Logical)
- func (b *SemanticAnalyzer) VisitMessage(node *Message)
- func (b *SemanticAnalyzer) VisitNoOp(node *NoOp)
- func (b *SemanticAnalyzer) VisitNumber(node *Number)
- func (b *SemanticAnalyzer) VisitPackage(node *Package)
- func (b *SemanticAnalyzer) VisitPrint(node *Print)
- func (b *SemanticAnalyzer) VisitProgram(node *Program)
- func (b *SemanticAnalyzer) VisitReturn(node *Return)
- func (b *SemanticAnalyzer) VisitString(node *String)
- func (b *SemanticAnalyzer) VisitType(node *Type)
- func (b *SemanticAnalyzer) VisitUnaryOp(node *UnaryOp)
- func (b *SemanticAnalyzer) VisitVar(node *Var)
- func (b *SemanticAnalyzer) VisitVarDecl(node *VarDecl)
- func (b *SemanticAnalyzer) VisitWhile(node *While)
- type String
- type Symbol
- type Token
- type TokenType
- type Type
- type UnaryOp
- type Var
- type VarDecl
- type VarSymbol
- type While
Constants ¶
View Source
const ( TokenPlus = "+" TokenMinus = "-" TokenMultiply = "*" TokenFloatDiv = "/" TokenLParen = "(" TokenRParen = ")" TokenLSquare = "[" TokenRSquare = "]" TokenLCurly = "{" TokenRCurly = "}" TokenSemi = ";" TokenDot = "." TokenColon = ":" TokenComma = "," TokenProgram = "PROGRAM" TokenImport = "IMPORT" TokenInteger = "INTEGER" TokenFloat = "FLOAT" TokenString = "STRING" TokenBoolean = "BOOLEAN" TokenList = "LIST" TokenDict = "DICT" TokenMessage = "MESSAGE" TokenIntegerDiv = "DIV" TokenVar = "VAR" TokenFunction = "FUNCTION" TokenBegin = "BEGIN" TokenEnd = "END" TokenReturn = "RETURN" TokenPrint = "PRINT" TokenID = "ID" TokenIntegerConst = "INTEGER_CONST" TokenFloatConst = "FLOAT_CONST" TokenStringConst = "STRING_CONST" TokenMessageConst = "MESSAGE_CONST" TokenAssign = ":=" TokenEOF = "EOF" TokenIf = "IF" TokenThen = "THEN" TokenElse = "ELSE" TokenWhile = "WHILE" TokenDo = "DO" TokenOr = "OR" TokenAnd = "AND" TokenTrue = "TRUE" TokenFalse = "FALSE" TokenEqual = "==" TokenNotEqual = "!=" TokenGreater = ">" TokenGreaterEqual = ">=" TokenLess = "<" TokenLessEqual = "<=" TokenAt = "@" TokenHash = "#" )
View Source
const BuiltinPackage = "builtin"
Variables ¶
View Source
var ReservedKeywords = map[string]Token{ "PROGRAM": {Type: TokenProgram, Value: TokenProgram}, "IMPORT": {Type: TokenImport, Value: TokenImport}, "FUNC": {Type: TokenFunction, Value: TokenFunction}, "VAR": {Type: TokenVar, Value: TokenVar}, "DIV": {Type: TokenIntegerDiv, Value: TokenIntegerDiv}, "INT": {Type: TokenInteger, Value: TokenInteger}, "FLOAT": {Type: TokenFloat, Value: TokenFloat}, "STRING": {Type: TokenString, Value: TokenString}, "BOOL": {Type: TokenBoolean, Value: TokenBoolean}, "BEGIN": {Type: TokenBegin, Value: TokenBegin}, "END": {Type: TokenEnd, Value: TokenEnd}, "IF": {Type: TokenIf, Value: TokenIf}, "THEN": {Type: TokenThen, Value: TokenThen}, "ELSE": {Type: TokenElse, Value: TokenElse}, "WHILE": {Type: TokenWhile, Value: TokenWhile}, "DO": {Type: TokenDo, Value: TokenDo}, "OR": {Type: TokenOr, Value: TokenOr}, "AND": {Type: TokenAnd, Value: TokenAnd}, "TRUE": {Type: TokenTrue, Value: true}, "FALSE": {Type: TokenFalse, Value: false}, "PRINT": {Type: TokenPrint, Value: TokenPrint}, "RETURN": {Type: TokenReturn, Value: TokenReturn}, "LIST": {Type: TokenList, Value: TokenList}, "DICT": {Type: TokenDict, Value: TokenDict}, "MESSAGE": {Type: TokenMessage, Value: TokenMessage}, }
Functions ¶
This section is empty.
Types ¶
type ActivationRecord ¶
type ActivationRecord struct { Name string Type ARType NestingLevel int Members map[string]interface{} ReturnValue interface{} }
func NewActivationRecord ¶
func NewActivationRecord(name string, t ARType, nestingLevel int) *ActivationRecord
func (*ActivationRecord) Get ¶
func (r *ActivationRecord) Get(key string) interface{}
func (*ActivationRecord) Set ¶
func (r *ActivationRecord) Set(key string, value interface{})
func (*ActivationRecord) String ¶
func (r *ActivationRecord) String() string
type Boolean ¶
func NewBoolean ¶
type BuiltinTypeSymbol ¶
func NewBuiltinTypeSymbol ¶
func NewBuiltinTypeSymbol(name string) *BuiltinTypeSymbol
func (*BuiltinTypeSymbol) String ¶
func (s *BuiltinTypeSymbol) String() string
type CallFunc ¶
type CallFunc func(i *Interpreter, args []interface{}) interface{}
type CallStack ¶
type CallStack struct {
// contains filtered or unexported fields
}
func NewCallStack ¶
func NewCallStack() *CallStack
func (*CallStack) Peek ¶
func (s *CallStack) Peek() *ActivationRecord
func (*CallStack) Pop ¶
func (s *CallStack) Pop() *ActivationRecord
func (*CallStack) Push ¶
func (s *CallStack) Push(ar *ActivationRecord)
type Compound ¶
type Compound struct {
Children []Ast
}
func NewCompound ¶
func NewCompound() *Compound
type FunctionCall ¶
type FunctionCall struct { PackageName string FuncName string ActualParams []Ast Token *Token FuncSymbol Symbol }
func NewFunctionCall ¶
func NewFunctionCall(packageName string, funcName string, actualParams []Ast, token *Token) *FunctionCall
type FunctionDecl ¶
type FunctionDecl struct { PackageName string FuncName string FormalParams []Ast BlockNode Ast ReturnType Ast }
func NewFunctionDecl ¶
func NewFunctionDecl(funcName string, formalParams []Ast, blockNode Ast, returnType Ast) *FunctionDecl
type FunctionRef ¶
func NewFunctionRef ¶
func NewFunctionRef(packageName string, funcName string, token *Token) *FunctionRef
type FunctionSymbol ¶
type FunctionSymbol struct { Package string Name string FormalParams []Ast ReturnType Ast BlockAst Ast ScopeLevel int Call CallFunc }
func NewFunctionSymbol ¶
func NewFunctionSymbol(name string) *FunctionSymbol
func (*FunctionSymbol) String ¶
func (s *FunctionSymbol) String() string
type Interpreter ¶
type Interpreter struct {
// contains filtered or unexported fields
}
func NewInterpreter ¶
func NewInterpreter(tree Ast) *Interpreter
func (*Interpreter) Interpret ¶
func (i *Interpreter) Interpret() (float64, error)
func (*Interpreter) Stdout ¶
func (i *Interpreter) Stdout() string
func (*Interpreter) Visit ¶
func (i *Interpreter) Visit(node Ast) interface{}
func (*Interpreter) VisitAssign ¶
func (i *Interpreter) VisitAssign(node *Assign) float64
func (*Interpreter) VisitBinOp ¶
func (i *Interpreter) VisitBinOp(node *BinOp) float64
func (*Interpreter) VisitBlock ¶
func (i *Interpreter) VisitBlock(node *Block) float64
func (*Interpreter) VisitBoolean ¶
func (i *Interpreter) VisitBoolean(node *Boolean) bool
func (*Interpreter) VisitCompound ¶
func (i *Interpreter) VisitCompound(node *Compound) float64
func (*Interpreter) VisitDict ¶
func (i *Interpreter) VisitDict(node *Dict) map[string]interface{}
func (*Interpreter) VisitFunctionCall ¶
func (i *Interpreter) VisitFunctionCall(node *FunctionCall) interface{}
func (*Interpreter) VisitFunctionDecl ¶
func (i *Interpreter) VisitFunctionDecl(node *FunctionDecl) float64
func (*Interpreter) VisitFunctionRef ¶
func (i *Interpreter) VisitFunctionRef(node *FunctionRef) *FunctionRef
func (*Interpreter) VisitIf ¶
func (i *Interpreter) VisitIf(node *If) interface{}
func (*Interpreter) VisitList ¶
func (i *Interpreter) VisitList(node *List) []interface{}
func (*Interpreter) VisitLogical ¶
func (i *Interpreter) VisitLogical(node *Logical) bool
func (*Interpreter) VisitMessage ¶
func (i *Interpreter) VisitMessage(node *Message) interface{}
func (*Interpreter) VisitNoOp ¶
func (i *Interpreter) VisitNoOp(node *NoOp) float64
func (*Interpreter) VisitNumber ¶
func (i *Interpreter) VisitNumber(node *Number) float64
func (*Interpreter) VisitPackage ¶
func (i *Interpreter) VisitPackage(node *Package) float64
func (*Interpreter) VisitPrint ¶
func (i *Interpreter) VisitPrint(node *Print) interface{}
func (*Interpreter) VisitProgram ¶
func (i *Interpreter) VisitProgram(node *Program) float64
func (*Interpreter) VisitReturn ¶
func (i *Interpreter) VisitReturn(node *Return) interface{}
func (*Interpreter) VisitString ¶
func (i *Interpreter) VisitString(node *String) string
func (*Interpreter) VisitType ¶
func (i *Interpreter) VisitType(node *Type) float64
func (*Interpreter) VisitUnaryOp ¶
func (i *Interpreter) VisitUnaryOp(node *UnaryOp) float64
func (*Interpreter) VisitVar ¶
func (i *Interpreter) VisitVar(node *Var) interface{}
func (*Interpreter) VisitVarDecl ¶
func (i *Interpreter) VisitVarDecl(node *VarDecl) float64
func (*Interpreter) VisitWhile ¶
func (i *Interpreter) VisitWhile(node *While) float64
type Lexer ¶
func (*Lexer) GetNextToken ¶
func (*Lexer) SkipComment ¶
func (l *Lexer) SkipComment()
func (*Lexer) SkipWhitespace ¶
func (l *Lexer) SkipWhitespace()
type Parser ¶
func (*Parser) AssignmentStatement ¶
func (*Parser) Comparison ¶
func (*Parser) CompoundStatement ¶
func (*Parser) Declarations ¶
func (*Parser) Expression ¶
func (*Parser) FormalParameterList ¶
func (*Parser) FormalParameters ¶
func (*Parser) FunctionCallStatement ¶
func (*Parser) FunctionDeclaration ¶
func (*Parser) FunctionReference ¶
func (*Parser) IfStatement ¶
func (*Parser) PrintStatement ¶
func (*Parser) ReturnStatement ¶
func (*Parser) StatementList ¶
func (*Parser) VariableDeclaration ¶
func (*Parser) WhileStatement ¶
type ScopedSymbolTable ¶
type ScopedSymbolTable struct { ScopeName string ScopeLevel int EnclosingScope *ScopedSymbolTable // contains filtered or unexported fields }
func NewScopedSymbolTable ¶
func NewScopedSymbolTable(scopeName string, scopeLevel int, enclosingScope *ScopedSymbolTable) *ScopedSymbolTable
func (*ScopedSymbolTable) Insert ¶
func (t *ScopedSymbolTable) Insert(symbol Symbol)
func (*ScopedSymbolTable) Lookup ¶
func (t *ScopedSymbolTable) Lookup(name string, currentScopeOnly bool) Symbol
func (*ScopedSymbolTable) String ¶
func (t *ScopedSymbolTable) String() string
type SemanticAnalyzer ¶
type SemanticAnalyzer struct {
CurrentScope *ScopedSymbolTable
}
func NewSemanticAnalyzer ¶
func NewSemanticAnalyzer() *SemanticAnalyzer
func (*SemanticAnalyzer) Visit ¶
func (b *SemanticAnalyzer) Visit(node Ast)
func (*SemanticAnalyzer) VisitAssign ¶
func (b *SemanticAnalyzer) VisitAssign(node *Assign)
func (*SemanticAnalyzer) VisitBinOp ¶
func (b *SemanticAnalyzer) VisitBinOp(node *BinOp)
func (*SemanticAnalyzer) VisitBlock ¶
func (b *SemanticAnalyzer) VisitBlock(node *Block)
func (*SemanticAnalyzer) VisitBoolean ¶
func (b *SemanticAnalyzer) VisitBoolean(node *Boolean)
func (*SemanticAnalyzer) VisitCompound ¶
func (b *SemanticAnalyzer) VisitCompound(node *Compound)
func (*SemanticAnalyzer) VisitDict ¶
func (b *SemanticAnalyzer) VisitDict(node *Dict)
func (*SemanticAnalyzer) VisitFunctionCall ¶
func (b *SemanticAnalyzer) VisitFunctionCall(node *FunctionCall)
func (*SemanticAnalyzer) VisitFunctionDecl ¶
func (b *SemanticAnalyzer) VisitFunctionDecl(node *FunctionDecl)
func (*SemanticAnalyzer) VisitFunctionRef ¶
func (b *SemanticAnalyzer) VisitFunctionRef(node *FunctionRef)
func (*SemanticAnalyzer) VisitIf ¶
func (b *SemanticAnalyzer) VisitIf(node *If)
func (*SemanticAnalyzer) VisitList ¶
func (b *SemanticAnalyzer) VisitList(node *List)
func (*SemanticAnalyzer) VisitLogical ¶
func (b *SemanticAnalyzer) VisitLogical(node *Logical)
func (*SemanticAnalyzer) VisitMessage ¶
func (b *SemanticAnalyzer) VisitMessage(node *Message)
func (*SemanticAnalyzer) VisitNoOp ¶
func (b *SemanticAnalyzer) VisitNoOp(node *NoOp)
func (*SemanticAnalyzer) VisitNumber ¶
func (b *SemanticAnalyzer) VisitNumber(node *Number)
func (*SemanticAnalyzer) VisitPackage ¶
func (b *SemanticAnalyzer) VisitPackage(node *Package)
func (*SemanticAnalyzer) VisitPrint ¶
func (b *SemanticAnalyzer) VisitPrint(node *Print)
func (*SemanticAnalyzer) VisitProgram ¶
func (b *SemanticAnalyzer) VisitProgram(node *Program)
func (*SemanticAnalyzer) VisitReturn ¶
func (b *SemanticAnalyzer) VisitReturn(node *Return)
func (*SemanticAnalyzer) VisitString ¶
func (b *SemanticAnalyzer) VisitString(node *String)
func (*SemanticAnalyzer) VisitType ¶
func (b *SemanticAnalyzer) VisitType(node *Type)
func (*SemanticAnalyzer) VisitUnaryOp ¶
func (b *SemanticAnalyzer) VisitUnaryOp(node *UnaryOp)
func (*SemanticAnalyzer) VisitVar ¶
func (b *SemanticAnalyzer) VisitVar(node *Var)
func (*SemanticAnalyzer) VisitVarDecl ¶
func (b *SemanticAnalyzer) VisitVarDecl(node *VarDecl)
func (*SemanticAnalyzer) VisitWhile ¶
func (b *SemanticAnalyzer) VisitWhile(node *While)
type UnaryOp ¶
func NewUnaryOp ¶
type VarDecl ¶
func NewVarDecl ¶
type VarSymbol ¶
func NewVarSymbol ¶
Click to show internal directories.
Click to hide internal directories.