Documentation
¶
Overview ¶
Parser package is responsible for parsing the tokens from the lexer and constructing the AST.
It uses the lexer to process tokens one at a time and records any parser errors in Errors slice. Registered prefix and infix parsing functions for different token types allow the parser to parse different expressions and statements.
Index ¶
Constants ¶
const ( LOWEST int EQUALS // == LESSGREATER // > or < SUM // + PRODUCT // * PREFIX // -X or !X CALL // myFunction(X) INDEX // array[index] ASSIGN // = )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Parser ¶
type Parser struct {
// stores all the parsing errors
Errors []*ParserError
// contains filtered or unexported fields
}
Parser is responsible for parsing the tokens from the lexer and constructing the AST It uses the lexer to process tokens one at a time and records any parser errors in Errors slice Registered prefix and infix parsing functions for different token types allows the parser to parse different expressions and statements
func (*Parser) ParseProgram ¶
ParseProgram parses the program and returns the AST
type ParserError ¶
type ParserError struct {
Message string // Parsing error message
Stack []uintptr // Stack trace
Line int // Line number where the error occurred
Column int // Column number where the error occurred
}
ParserError is an error type that is returned when a parsing error occurs.
func (*ParserError) Error ¶
func (e *ParserError) Error() string
Error creates a new ParserError with the given message, line, column, and stack trace.