parser

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LOWEST      int
	EQUALS      // ==
	LESSGREATER // > or <
	SUM         // +
	PRODUCT     // *
	PREFIX      // -X or !X
	CALL        // myFunction(X)
	INDEX       // array[index]
)

Define precedences. Using iota to give constants incrementing numbers as values. The higher the value, the higher precedence it has.

Variables

This section is empty.

Functions

This section is empty.

Types

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser constructs the abstract syntax-tree for a program by analyzing the tokens produced by a Lexer. It holds information on the Lexer that is producing tokens, the current token being parsed (curToken), the next token (peekToken), the errors that were encountered during parsing and maps of its tokens with their parsing functions.

func New

func New(l *lexer.Lexer) *Parser

New creates a new instance of a Parser with the first two tokens read

func (*Parser) Errors

func (p *Parser) Errors() []string

Errors returns the errors in the parser

func (*Parser) ParseProgram

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

ParseProgram constructs the root node of a AST an *ast.Program. It then iterates over every token from the lexer until it encounters an token.EOF token.

Jump to

Keyboard shortcuts

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