Documentation
¶
Index ¶
- func AddImport(p *Program, path string)
- func CheckTypes(p *Program) error
- func CountNodes(n Node) int
- func PrettyPrint(p *Program) string
- func Walk(n Node, v Visitor)
- type BlockStatement
- type CallExpression
- type Expression
- type ExpressionStatement
- type Function
- type Identifier
- type IfStatement
- type Import
- type InfixExpression
- type IntegerLiteral
- type Module
- type Node
- type Parameter
- type ParseError
- type Parser
- type Program
- type ReturnStatement
- type Statement
- type StringLiteral
- type SymbolTable
- type VarStatement
- type Visitor
- type WhileStatement
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckTypes ¶
CheckTypes performs a very small type-check pass validating declared types used in variable declarations and function return types. It's intentionally conservative and only recognizes "int" and "string" for now.
func CountNodes ¶
CountNodes returns the total number of nodes in the subtree rooted at n.
func PrettyPrint ¶
PrettyPrint produces a simple human-readable representation of the AST.
Types ¶
type BlockStatement ¶
type BlockStatement struct {
Statements []Statement
}
func (*BlockStatement) Children ¶
func (b *BlockStatement) Children() []Node
type CallExpression ¶
type CallExpression struct {
Function Expression
Args []Expression
}
func (*CallExpression) Children ¶
func (c *CallExpression) Children() []Node
type Expression ¶
type Expression interface{}
type ExpressionStatement ¶
type ExpressionStatement struct {
Expr Expression
}
func (*ExpressionStatement) Children ¶
func (e *ExpressionStatement) Children() []Node
type Function ¶
type Function struct {
Name string
ReturnType string
Body *BlockStatement
}
type Identifier ¶
type Identifier struct {
Value string
}
func (*Identifier) Children ¶
func (id *Identifier) Children() []Node
type IfStatement ¶
type IfStatement struct {
Condition Expression
Consequent *BlockStatement
Alternative *BlockStatement
}
IfStatement represents a simple if/else statement.
type Import ¶
type Import struct {
Path string
}
Import represents a simple import directive in the source.
type InfixExpression ¶
type InfixExpression struct {
Left Expression
Operator string
Right Expression
}
func (*InfixExpression) Children ¶
func (in *InfixExpression) Children() []Node
type IntegerLiteral ¶
type IntegerLiteral struct {
Value string
}
func (*IntegerLiteral) Children ¶
func (i *IntegerLiteral) Children() []Node
type Module ¶
Module groups multiple AST files into a single compilation unit.
func (*Module) TotalNodes ¶
TotalNodes returns total node count across all files in the module.
type Node ¶
type Node interface {
Children() []Node
}
Node is a generic AST node used by helpers and visitors.
type ParseError ¶
ParseError represents a parser error with optional position information.
func (*ParseError) Error ¶
func (e *ParseError) Error() string
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
func (*Parser) ParseProgram ¶
type ReturnStatement ¶
type ReturnStatement struct {
Value Expression
}
func (*ReturnStatement) Children ¶
func (r *ReturnStatement) Children() []Node
type StringLiteral ¶
type StringLiteral struct {
Value string
}
func (*StringLiteral) Children ¶
func (s *StringLiteral) Children() []Node
type SymbolTable ¶
SymbolTable is a minimal symbol table tracking functions and variables.
func NewSymbolTable ¶
func NewSymbolTable() *SymbolTable
func (*SymbolTable) LookupFunc ¶
func (s *SymbolTable) LookupFunc(name string) (*Function, bool)
func (*SymbolTable) RegisterFunc ¶
func (s *SymbolTable) RegisterFunc(f *Function)
func (*SymbolTable) RegisterVar ¶
func (s *SymbolTable) RegisterVar(name, typ string)
type VarStatement ¶
type VarStatement struct {
Name string
Type string
Value Expression
}
func (*VarStatement) Children ¶
func (v *VarStatement) Children() []Node
type WhileStatement ¶
type WhileStatement struct {
Condition Expression
Body *BlockStatement
}
WhileStatement represents a while loop.