ast

package
v0.3.3-alpha Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Argument

type Argument struct {
	Name string
	Type ValueType
}

type BlockStatement

type BlockStatement struct {
	Token      lexer.Token
	Statements []Statement
}

func (*BlockStatement) String

func (bs *BlockStatement) String() string

func (*BlockStatement) TokenLiteral

func (bs *BlockStatement) TokenLiteral() string

func (*BlockStatement) ValueType

func (bs *BlockStatement) ValueType() ValueType

type CharLiteral

type CharLiteral struct {
	Token lexer.Token
	Value byte
}

func (*CharLiteral) String

func (cl *CharLiteral) String() string

func (*CharLiteral) TokenLiteral

func (cl *CharLiteral) TokenLiteral() string

func (*CharLiteral) ValueType

func (fl *CharLiteral) ValueType() ValueType

type Expression

type Expression interface {
	Node
	// contains filtered or unexported methods
}

type ExpressionStatement

type ExpressionStatement struct {
	Token      lexer.Token
	Expression Expression
}

func (*ExpressionStatement) String

func (es *ExpressionStatement) String() string

func (*ExpressionStatement) TokenLiteral

func (es *ExpressionStatement) TokenLiteral() string

func (*ExpressionStatement) ValueType

func (es *ExpressionStatement) ValueType() ValueType

type FloatLiteral

type FloatLiteral struct {
	Token lexer.Token
	Value float64
	Type  ValueType
}

func (*FloatLiteral) String

func (fl *FloatLiteral) String() string

func (*FloatLiteral) TokenLiteral

func (fl *FloatLiteral) TokenLiteral() string

func (*FloatLiteral) ValueType

func (fl *FloatLiteral) ValueType() ValueType

type Function

type Function struct {
	Name            string
	ReturnType      ValueType
	Statement       Statement
	SymbolIndex     map[string]int
	Symbols         []*Symbol
	NextSymbolIndex int
	Arguments       []Argument
}

func NewFunction

func NewFunction(name string, returnType ValueType) *Function

func (*Function) GetSymbol

func (f *Function) GetSymbol(name string) *Symbol

func (*Function) GetVariableCounts

func (f *Function) GetVariableCounts() (integerCount, floatCount int)

func (*Function) SetSymbol

func (f *Function) SetSymbol(name string, t ValueType, constant bool) *Symbol

func (*Function) String

func (f *Function) String() string

func (*Function) TokenLiteral

func (f *Function) TokenLiteral() string

func (*Function) ValueType

func (f *Function) ValueType() ValueType

type FunctionCallExpression

type FunctionCallExpression struct {
	Token      lexer.Token
	Name       string
	Args       []Expression
	ReturnType ValueType
	Index      int
}

func (*FunctionCallExpression) String

func (fce *FunctionCallExpression) String() string

func (*FunctionCallExpression) TokenLiteral

func (fce *FunctionCallExpression) TokenLiteral() string

func (*FunctionCallExpression) ValueType

func (fce *FunctionCallExpression) ValueType() ValueType

type Identifier

type Identifier struct {
	Token  lexer.Token
	Value  string
	Symbol *Symbol
}

func (*Identifier) String

func (i *Identifier) String() string

func (*Identifier) TokenLiteral

func (i *Identifier) TokenLiteral() string

func (*Identifier) ValueType

func (i *Identifier) ValueType() ValueType

type IfStatement

type IfStatement struct {
	Token       lexer.Token
	Condition   Expression
	Consequence Statement
	Alternative Statement
}

func (*IfStatement) String

func (i *IfStatement) String() string

func (*IfStatement) TokenLiteral

func (i *IfStatement) TokenLiteral() string

func (*IfStatement) ValueType

func (i *IfStatement) ValueType() ValueType

type InfixExpression

type InfixExpression struct {
	Token    lexer.Token
	Left     Expression
	Operator string
	Right    Expression
}

func (*InfixExpression) String

func (ie *InfixExpression) String() string

func (*InfixExpression) TokenLiteral

func (ie *InfixExpression) TokenLiteral() string

func (*InfixExpression) ValueType

func (ie *InfixExpression) ValueType() ValueType

type IntegerLiteral

type IntegerLiteral struct {
	Token lexer.Token
	Value int64
	Type  ValueType
}

func (*IntegerLiteral) String

func (il *IntegerLiteral) String() string

func (*IntegerLiteral) TokenLiteral

func (il *IntegerLiteral) TokenLiteral() string

func (*IntegerLiteral) ValueType

func (il *IntegerLiteral) ValueType() ValueType

type Node

type Node interface {
	TokenLiteral() string
	String() string
	ValueType() ValueType
}

type PostfixExpression

type PostfixExpression struct {
	Token    lexer.Token
	Left     Expression
	Operator string
}

func (*PostfixExpression) String

func (pe *PostfixExpression) String() string

func (*PostfixExpression) TokenLiteral

func (pe *PostfixExpression) TokenLiteral() string

func (*PostfixExpression) ValueType

func (pe *PostfixExpression) ValueType() ValueType

type PrefixExpression

type PrefixExpression struct {
	Token    lexer.Token
	Operator string
	Right    Expression
}

func (*PrefixExpression) String

func (pe *PrefixExpression) String() string

func (*PrefixExpression) TokenLiteral

func (pe *PrefixExpression) TokenLiteral() string

func (*PrefixExpression) ValueType

func (pe *PrefixExpression) ValueType() ValueType

type Program

type Program struct {
	Functions []*Function

	// Functions to be imported from JS
	ExternalFunctions []*Function

	// global statements
	Statements []Statement
}

func (*Program) FunctionExists

func (p *Program) FunctionExists(name string) int

checks if a function exists, if so returns it's index. otherwise the function returns -1

func (*Program) String

func (p *Program) String() string

func (*Program) TokenLiteral

func (p *Program) TokenLiteral() string

func (*Program) Type

func (p *Program) Type() ValueType

type ReturnStatement

type ReturnStatement struct {
	Token       lexer.Token
	ReturnValue Expression
}

func (*ReturnStatement) String

func (rs *ReturnStatement) String() string

func (*ReturnStatement) TokenLiteral

func (rs *ReturnStatement) TokenLiteral() string

func (*ReturnStatement) ValueType

func (rs *ReturnStatement) ValueType() ValueType

type Statement

type Statement interface {
	Node
	// contains filtered or unexported methods
}

type Symbol

type Symbol struct {
	Index    int
	Type     ValueType
	Constant bool
}

type ValueType

type ValueType string
const (
	ValueTypeInt   ValueType = "int"
	ValueTypeFloat ValueType = "float"
	ValueTypeChar  ValueType = "char"
	ValueTypeVoid  ValueType = "void"
)

type VariableDefineStatement

type VariableDefineStatement struct {
	Token lexer.Token
	Name  *Identifier
	Value Expression
	Type  ValueType
}

func (*VariableDefineStatement) String

func (vds *VariableDefineStatement) String() string

func (*VariableDefineStatement) TokenLiteral

func (vds *VariableDefineStatement) TokenLiteral() string

func (*VariableDefineStatement) ValueType

func (vds *VariableDefineStatement) ValueType() ValueType

type VariableUpdateStatement

type VariableUpdateStatement struct {
	Name      *Identifier
	Token     lexer.Token
	NewValue  Expression
	Operation string
}

func (*VariableUpdateStatement) String

func (vus *VariableUpdateStatement) String() string

func (*VariableUpdateStatement) TokenLiteral

func (vus *VariableUpdateStatement) TokenLiteral() string

func (*VariableUpdateStatement) ValueType

func (vus *VariableUpdateStatement) ValueType() ValueType

type WhileLoopStatement

type WhileLoopStatement struct {
	Token     lexer.Token
	Condition Expression
	Statement Statement
}

func (*WhileLoopStatement) String

func (ws *WhileLoopStatement) String() string

func (*WhileLoopStatement) TokenLiteral

func (ws *WhileLoopStatement) TokenLiteral() string

func (*WhileLoopStatement) ValueType

func (ws *WhileLoopStatement) ValueType() ValueType

Jump to

Keyboard shortcuts

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