Documentation
¶
Index ¶
- Constants
- Variables
- func GetCurrentToken() lexer.Token
- func GetNextToken() lexer.Token
- func IsNextToken(kind lexer.TokenKind) bool
- func IsNotEOF() bool
- func MoveNextWith(kind lexer.TokenKind, message string) lexer.Token
- func MoveToNextToken()
- func PanicWithDetails(token lexer.Token, message string)
- func ParseAdditiveExpression() interface{}
- func ParseAssignmentExpression() interface{}
- func ParseExpression() interface{}
- func ParseMultiplicativeExpression() interface{}
- func ParsePrimaryExpression() interface{}
- func ParseStatement() interface{}
- func ParseVariableDeclarationStatement() interface{}
- type AssignmentExpression
- type BinaryExpression
- type Expression
- type IdentifierExpression
- type Node
- type NumericLiteralExpression
- type Program
- type Statement
- type UnaryExpression
- type VariableDeclarationStatement
Constants ¶
const ( ProgramNode = iota IdentifierExpressionNode NumericLiteralExpressionNode UnaryExpressionNode BinaryExpressionNode AssignmentExpressionNode VariableDeclarationStatementNode )
Variables ¶
var CurrentIndex int = 0
var CurrentTokens []lexer.Token = []lexer.Token{}
var NodeTypeNames = map[int]string{ ProgramNode: "ProgramNode", IdentifierExpressionNode: "IdentifierExpressionNode", UnaryExpressionNode: "UnaryExpressionNode", NumericLiteralExpressionNode: "NumericLiteralExpressionNode", BinaryExpressionNode: "BinaryExpressionNode", AssignmentExpressionNode: "AssignmentExpressionNode", VariableDeclarationStatementNode: "VariableDeclarationStatementNode", }
Functions ¶
func GetCurrentToken ¶
func GetNextToken ¶
func IsNextToken ¶
func MoveToNextToken ¶
func MoveToNextToken()
func PanicWithDetails ¶
func ParseAdditiveExpression ¶
func ParseAdditiveExpression() interface{}
ParseAdditiveExpression parses an additive expression e.g.: 1 + 2 e.g.: (1 + 2) - 3
func ParseAssignmentExpression ¶
func ParseAssignmentExpression() interface{}
ParseAssignmentExpression parses an assignment expression e.g.: a = 1
func ParseExpression ¶
func ParseExpression() interface{}
Precedence: 1. PrimaryExpression 2. UnaryExpression 3. MultiplicativeExpression 4. AdditiveExpression 5. AssignmentExpression
func ParseMultiplicativeExpression ¶
func ParseMultiplicativeExpression() interface{}
ParseMultiplicativeExpression parses a multiplicative expression e.g. 1 * 2 e.g. (1 * 2) * 3
func ParsePrimaryExpression ¶
func ParsePrimaryExpression() interface{}
func ParseStatement ¶
func ParseStatement() interface{}
func ParseVariableDeclarationStatement ¶
func ParseVariableDeclarationStatement() interface{}
Types ¶
type AssignmentExpression ¶
type AssignmentExpression struct {
Expression
Symbol string `json:"symbol"`
Value interface{} `json:"value"`
}
AssignmentExpression is an assignment expression node that can be used to assign a value to a variable e.g. foo = 42
type BinaryExpression ¶
type BinaryExpression struct {
Expression
Operator string `json:"operator"`
Left interface{} `json:"left"`
Right interface{} `json:"right"`
}
BinaryExpression is a binary expression node that can be used to represent arithmetic operations and comparisons e.g. 1 + 2
type Expression ¶
Expression is a generic expression node that can be used as a base for more specific expression types
type IdentifierExpression ¶
type IdentifierExpression struct {
Expression
Symbol string `json:"symbol"`
}
Identifier is an identifier node that represents a variable or function name e.g. foo
func ParseIdentifier ¶
func ParseIdentifier() IdentifierExpression
ParseIdentifier parses an identifier expression e.g. foo
type NumericLiteralExpression ¶
type NumericLiteralExpression struct {
Expression
Value int `json:"value"`
}
NumericLiteral is a numeric literal node that represents a numeric value e.g. 42
func ParseNumericLiteral ¶
func ParseNumericLiteral() NumericLiteralExpression
ParseNumericLiteral parses a numeric literal expression e.g. 42
type Program ¶
type Program struct {
NodeType int `json:"nodeType"`
NodeName string `json:"nodeName"`
Statements []interface{} `json:"statements"`
}
func GenerateAst ¶
GenerateAst generates an abstract syntax tree (AST) from the input string and returns a Program struct containing the AST Precedence is based on the order of precedence in the language specification 1. PrimaryExpression 2. UnaryExpression 3. MultiplicativeExpression 4. AdditiveExpression
type UnaryExpression ¶
type UnaryExpression struct {
Expression
Operator string `json:"operator"`
Right interface{} `json:"right"`
}
UnaryExpression is a unary expression node that can be used to represent unary operations e.g. -42 - Unary Minus (-): This operation negates the value of a number, changing its sign e.g. !foo - Boolean Not (!): This operation inverts the boolean value of its operand e.g. &foo - Address-of (&): This operation returns the memory address of its operand e.g. *foo - Dereference (*): This operation accesses the value stored at a pointer's address