parser

package
v2.1.18 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2022 License: GPL-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package parser consumes tokens from the lexer and returns a program as a set of AST-nodes.

Later we walk the AST tree and generate a series of bytecode instructions.

Index

Constants

View Source
const (
	LOWEST  int
	TERNARY // ? :
	ASSIGN  // =
	COND    // OR or AND
	EQUALS  // == or !=
	CMP
	LESSGREATER // > or <
	SUM         // + or -
	PRODUCT     // * or /
	POWER       // **
	MOD         // %
	PREFIX      // -X or !X
	CALL        // myFunction(X)
	INDEX       // array[index], map[key]
)

Here we define values for precedence, lowest to highest.

Variables

This section is empty.

Functions

This section is empty.

Types

type Parser

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

Parser is the object which maintains our parser state.

We consume tokens, produced by our lexer, and so we need to keep track of our current token, the next token, and any errors we've seen, for example.

func New

func New(l *lexer.Lexer) *Parser

New returns a new parser.

Once constructed it can be used to parse an input-program into an AST.

func (*Parser) Errors

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

Errors return stored errors

func (*Parser) Parse added in v2.1.14

func (p *Parser) Parse() (*ast.Program, error)

Parse is the main public-facing method to parse an input program.

It will return any error-encountered in parsing the input, but to avoid confusion it will only return the first error.

To access any subsequent errors please see `Errors`.

func (*Parser) ParseProgram

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

ParseProgram used to parse the whole program

Jump to

Keyboard shortcuts

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