Documentation
¶
Index ¶
- type Argument
- type BlockStatement
- type CharLiteral
- type Expression
- type ExpressionStatement
- type FloatLiteral
- type ForLoopStatement
- type Function
- func (f *Function) GetSymbol(name string) *Symbol
- func (f *Function) GetVariableCounts() (integerCount, floatCount int)
- func (f *Function) SetSymbol(name string, t ValueType, constant bool) *Symbol
- func (f *Function) String() string
- func (f *Function) TokenLiteral() string
- func (f *Function) ValueType() ValueType
- type FunctionCallExpression
- type Identifier
- type IfStatement
- type InfixExpression
- type IntegerLiteral
- type Node
- type PostfixExpression
- type PrefixExpression
- type Program
- type ReturnStatement
- type Statement
- type Symbol
- type ValueType
- type VariableDefineStatement
- type VariableUpdateStatement
- type WhileLoopStatement
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BlockStatement ¶
Represents a block of code contained within {}
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 ¶
Represents a character literal (e.g. 'a', 'b', '\n')
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
}
Represents an expression (e.g. 5 < 2, 6 + 7, 5 * (3 + 5))
type ExpressionStatement ¶
type ExpressionStatement struct {
Token lexer.Token
Expression Expression
}
Represents a standalone expression statement
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 ¶
Represents a literal float (e.g. 5.0, 3.14159, -0.56791)
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 ForLoopStatement ¶
type ForLoopStatement struct {
Token lexer.Token
Initial Statement // initial statement (e.g. int i = 0;)
Condition Expression // stopping condition (e.g. i < 10;)
Increment Expression // code to run every iteration (e.g. i++)
Statement Statement // actual code to run throughout the loop
}
Represents a for loop
func (*ForLoopStatement) String ¶
func (fs *ForLoopStatement) String() string
func (*ForLoopStatement) TokenLiteral ¶
func (fs *ForLoopStatement) TokenLiteral() string
func (*ForLoopStatement) ValueType ¶
func (fs *ForLoopStatement) ValueType() ValueType
type Function ¶
type Function struct {
Name string
ReturnType ValueType
Statement Statement
SymbolIndex map[string]int
Symbols []*Symbol
NextSymbolIndex int
Arguments []Argument
}
Represents a function in the program
func NewFunction ¶
func (*Function) GetVariableCounts ¶
Gets the number of variables based on each main type, used to generate WASM locals to store the variables in
func (*Function) TokenLiteral ¶
type FunctionCallExpression ¶
type FunctionCallExpression struct {
Token lexer.Token
Name string
Args []Expression
ReturnType ValueType
Index int
}
Represents a call to a function in an expression
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 ¶
Represents an identifier expression (e.g. using a variable in an expression)
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
}
Represents an if statement in the AST
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
}
Represents an expression with an operator and two values (e.g. 5 + 6)
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 ¶
Represents a literal integer (e.g. 5, 682329, -2198)
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 {
// Returns the TokenLiteral of the AST Node
TokenLiteral() string
// Returns a string representation of the AST Node
String() string
// Returns the type of the AST Node
ValueType() ValueType
}
Represents a Node in the Abstract Syntax Tree
type PostfixExpression ¶
type PostfixExpression struct {
Token lexer.Token
Left Expression
Operator string
}
Represents an expression with it's operator on the right side (e.g. 5++, i--)
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
}
Represents an expression with a prefix operator (e.g. -5, +6)
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 {
// Every function declared
Functions []*Function
// Functions to be imported from JS
ExternalFunctions []*Function
// global statements
Statements []Statement
}
Stores the entire program and it's AST
func (*Program) FunctionExists ¶
checks if a function exists, if so returns it's index. otherwise the function returns -1
func (*Program) TokenLiteral ¶
type ReturnStatement ¶
type ReturnStatement struct {
Token lexer.Token
ReturnValue Expression
}
Represents a statement that returns a value from a function
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
}
Represents a statement node (e.g. variable declaration, if statement etc.) in the AST
type ValueType ¶
type ValueType string
Represents a type within the C programming language Used mainly for storing return types of functions and statements within the AST
type VariableDefineStatement ¶
type VariableDefineStatement struct {
Token lexer.Token
Name *Identifier
Value Expression
Type ValueType
}
Represents a statement that defines a variable (e.g. int x = 0;)
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
}
Represents a statement that defines a variable (e.g. x = 5; x += 6;)
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
}
Represents a while loop
func (*WhileLoopStatement) String ¶
func (ws *WhileLoopStatement) String() string
func (*WhileLoopStatement) TokenLiteral ¶
func (ws *WhileLoopStatement) TokenLiteral() string
func (*WhileLoopStatement) ValueType ¶
func (ws *WhileLoopStatement) ValueType() ValueType