ast

package
v0.0.0-...-dc5b6fe Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2021 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	INCREMENT UnaryExprEnum = iota
	DECREMENT               = iota
	RETURN                  = iota
)

UNNARY_EXPR enum values

View Source
const (
	BINEXPR_ADD BinaryExprEnum = iota
	BINEXPR_SUB                = iota
	BINEXPR_MUL                = iota
	BINEXPR_DIV                = iota
	BINEXPR_MOD                = iota
)

BINARY_EXPR enum values

View Source
const (
	CONST_DEC    LiteralTypeEnum = iota
	CONST_OCT                    = iota
	CONST_HEX                    = iota
	CONST_FLOAT                  = iota
	CONST_DOUBLE                 = iota
	CONST_CHAR                   = iota
	CONST_STRING                 = iota
)

LiteralTypeEnum values

Variables

This section is empty.

Functions

func GetLineBeginChar

func GetLineBeginChar() string

func GetTabs

func GetTabs(tabLevel int) string

Types

type Assignment

type Assignment struct {
	BaseNode
	Variable      VariableReference
	Value         Node
	IsInitializer bool
}

Assignment represents a assignment to a variable

func NewAssignmentNode

func NewAssignmentNode(varRefName string) *Assignment

func (*Assignment) ToString

func (node *Assignment) ToString(tabLevel int) string

type AstBuilder

type AstBuilder struct {
	antlr.BaseLlamaLangVisitor
	Errors      []shared.Error
	Program     *Program
	GlobalScope *Scope
	// contains filtered or unexported fields
}

AstBuilder builds the ast by using visitor pattern in the parsing tree

func (*AstBuilder) Visit

func (builder *AstBuilder) Visit(tree antlr4.ParseTree) interface{}

func (*AstBuilder) VisitAssignment

func (builder *AstBuilder) VisitAssignment(ctx *antlr.AssignmentContext) interface{}

func (*AstBuilder) VisitBasicLit

func (builder *AstBuilder) VisitBasicLit(ctx *antlr.BasicLitContext) interface{}

func (*AstBuilder) VisitBlock

func (builder *AstBuilder) VisitBlock(ctx *antlr.BlockContext) interface{}

func (*AstBuilder) VisitChildren

func (builder *AstBuilder) VisitChildren(node antlr4.RuleNode) interface{}

func (*AstBuilder) VisitErrorNode

func (builder *AstBuilder) VisitErrorNode(errorNode antlr4.ErrorNode) interface{}

func (*AstBuilder) VisitExpression

func (builder *AstBuilder) VisitExpression(ctx *antlr.ExpressionContext) interface{}

func (*AstBuilder) VisitExpressionList

func (builder *AstBuilder) VisitExpressionList(ctx *antlr.ExpressionListContext) interface{}

func (*AstBuilder) VisitFunctionDef

func (builder *AstBuilder) VisitFunctionDef(ctx *antlr.FunctionDefContext) interface{}

func (*AstBuilder) VisitLiteral

func (builder *AstBuilder) VisitLiteral(ctx *antlr.LiteralContext) interface{}

func (*AstBuilder) VisitOperand

func (builder *AstBuilder) VisitOperand(ctx *antlr.OperandContext) interface{}

func (*AstBuilder) VisitOperandName

func (builder *AstBuilder) VisitOperandName(ctx *antlr.OperandNameContext) interface{}

func (*AstBuilder) VisitParameters

func (builder *AstBuilder) VisitParameters(ctx *antlr.ParametersContext) interface{}

func (*AstBuilder) VisitPrimaryExpr

func (builder *AstBuilder) VisitPrimaryExpr(ctx *antlr.PrimaryExprContext) interface{}

func (*AstBuilder) VisitReturnStmt

func (builder *AstBuilder) VisitReturnStmt(ctx *antlr.ReturnStmtContext) interface{}

func (*AstBuilder) VisitSignature

func (builder *AstBuilder) VisitSignature(ctx *antlr.SignatureContext) interface{}

func (*AstBuilder) VisitSimpleStmt

func (builder *AstBuilder) VisitSimpleStmt(ctx *antlr.SimpleStmtContext) interface{}

func (*AstBuilder) VisitSourceFile

func (builder *AstBuilder) VisitSourceFile(ctx *antlr.SourceFileContext) interface{}

func (*AstBuilder) VisitStatement

func (builder *AstBuilder) VisitStatement(ctx *antlr.StatementContext) interface{}

func (*AstBuilder) VisitStatementList

func (builder *AstBuilder) VisitStatementList(ctx *antlr.StatementListContext) interface{}

func (*AstBuilder) VisitUnaryExpr

func (builder *AstBuilder) VisitUnaryExpr(ctx *antlr.UnaryExprContext) interface{}

func (*AstBuilder) VisitVarDef

func (builder *AstBuilder) VisitVarDef(ctx *antlr.VarDefContext) interface{}

type BaseNode

type BaseNode struct {
	FileName   string
	LineNumber int
}

BaseNode is the Base AST type

type BinaryExprEnum

type BinaryExprEnum int

BinaryExprEnum enumType

type BinaryExpression

type BinaryExpression struct {
	Expression
	ExprID BinaryExprEnum
	Right  Node
	Left   Node
}

BinaryExpression are those that have two operands

type Expression

type Expression struct {
	BaseNode
}

Expression is the base node to represent expressions

func (*Expression) ToString

func (node *Expression) ToString(_ int) string

type FunctionDefinition

type FunctionDefinition struct {
	BaseNode
	Name       string
	RetType    string
	Parameters []*VariableDefinition
	Block      []Node
}

func (*FunctionDefinition) ToString

func (node *FunctionDefinition) ToString(tabLevel int) string

type LiteralConstant

type LiteralConstant struct {
	BaseNode
	ConstantID LiteralTypeEnum
	Value      string
}

LiteralConstant represents a literalConstant

func (*LiteralConstant) ToString

func (node *LiteralConstant) ToString(tabLevel int) string

type LiteralTypeEnum

type LiteralTypeEnum int

LiteralTypeEnum enumType

type Node

type Node interface {
	ToString(int) string
}

type Program

type Program struct {
	BaseNode
	Name     string
	Children []Node
}

Program is the ast node representing the whole program

func NewProgramNode

func NewProgramNode(executableName string) *Program

func (*Program) ToString

func (node *Program) ToString(tabLevel int) string

type Scope

type Scope struct {
	Children  []*Scope
	Parent    *Scope
	Data      Node
	ScopeType ScopeTypeEnum
	// contains filtered or unexported fields
}

Scope represent a symbol table for a given scope

func NewScope

func NewScope(scopeType ScopeTypeEnum, data Node, parent *Scope) *Scope

func (*Scope) AddChildren

func (scope *Scope) AddChildren(scopeType ScopeTypeEnum, name string, symbol *FunctionDefinition) *Scope

func (*Scope) AddSymbol

func (scope *Scope) AddSymbol(name string, symbol Node)

func (*Scope) FindSymbol

func (scope *Scope) FindSymbol(name string, justCurrent bool) Node

FindSymbol Finds a symbols in the scope

type ScopeTypeEnum

type ScopeTypeEnum int
const (
	GLOBAL_SCOPE   ScopeTypeEnum = iota
	FUNCTION_SCOPE               = iota
)

type UnaryExprEnum

type UnaryExprEnum int

UnaryExprEnum enumType

type UnaryExpression

type UnaryExpression struct {
	Expression
	ExprID UnaryExprEnum
	Value  Node
}

UnaryExpression are those that have only one operand

func (*UnaryExpression) ToString

func (node *UnaryExpression) ToString(tabLevel int) string

type VariableDefinition

type VariableDefinition struct {
	BaseNode
	Name                string
	VarType             string
	IsGlobal            bool
	IsParam             bool
	AssignmentStatement *Assignment
}

VariableDefinition represents a variable definition in the code

func (*VariableDefinition) ToString

func (node *VariableDefinition) ToString(tabLevel int) string

type VariableReference

type VariableReference struct {
	BaseNode
	VarName string
}

VariableReference represents a variable that is being referenced in a statement

func NewVariableReference

func NewVariableReference(varName string) *VariableReference

func (*VariableReference) ToString

func (node *VariableReference) ToString(tabLevel int) string

Jump to

Keyboard shortcuts

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