parser

package
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 28, 2025 License: MIT Imports: 7 Imported by: 0

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

View Source
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 New

func New(l *lexer.Lexer) *Parser

New creates a new Parser instance with the given lexer

func (*Parser) ParseProgram

func (p *Parser) ParseProgram() *ast.Program

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.

func (*ParserError) Format

func (e *ParserError) Format(s fmt.State, verb rune)

Format formats the ParserError for printing.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL