generator

package
v0.0.0-...-ef17ad3 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2020 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package generator implements a parser generator.

Package generator generates a parser which provides the function pgParse:

// pgParse returns an AST node.
func pgParse() pgNode

pgParse returns an AST node. The returned node is of the type of the start production of the grammar. If no production could be applied, a node with type "error" is returned.

An node looks like this:

// pgNode is an element in the abstract syntax tree.
type pgNode struct {
	typ      string // type, as defined in the grammar or "error"
	val      string // actual value or empty for non-terminal nodes
	children []pgNode // child nodes, empty for terminal nodes
}

pgParse uses pgLex to obtain the next lexical token. The client package must implement a function pgLex:

// pgLex is called to obtain the next
// lexical token tok of type typ. pgLex
// returns "$" to indicate end of input.
pgLex() (typ, tok string)

The client package must also implement a function pgError, which is called if an error occurs while parsing.

// pgError is called if an error
// occurred while parsing.
pgError(err error)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateSLR

func GenerateSLR(grammar ast.Grammar) ([]byte, error)

GenerateSLR generates an SLR(1) parser with suitable parse tables for a given grammar. The generated parser is gofmt'ed Go code.

Types

This section is empty.

Jump to

Keyboard shortcuts

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