Documentation
¶
Overview ¶
Package parser implements the syntactic analyzer for the Monkey programming language.
The parser takes a stream of tokens from the lexer and constructs an Abstract Syntax Tree (AST) that represents the structure of the program. It implements a recursive descent parser with Pratt parsing (precedence climbing) for expressions.
Key features:
- Top-down parsing of statements and expressions
- Precedence-based expression parsing
- Error reporting for syntax errors
- Support for all language constructs (statements, expressions, literals, etc.)
The main entry point is the New function, which creates a new Parser instance, and the Parser.ParseProgram method, which parses a complete Monkey program and returns an AST.
Index ¶
Constants ¶
const ( // Lowest represents the lowest possible precedence for parsing expressions in the syntax tree. Lowest int // Equals is the precedence for the equality operator. Equals // == // LessGreater is the precedence for the less-than and greater-than operators. LessGreater // > or < // Sum is the precedence for the sum operator. Sum // + // Product is the precedence for the product operator. Product // * // Prefix is the precedence for prefix operators. Prefix // -x or !x // Call is the precedence for function calls. Call // myFunc(x) // Index is the precedence for array indexing. Index // array[index] )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser represents a Monkey parser.
func (*Parser) ParseProgram ¶
ParseProgram parses a complete Monkey program and returns its AST representation. It processes tokens until it reaches the end of the input, building a list of statements.
Check Parser.Errors after calling this method to see if any parsing errors occurred.