lrparser

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2023 License: AGPL-3.0 Imports: 4 Imported by: 2

README

lrparser

An LR parser

Documentation

Overview

An LR-parser.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CoalesceSymbols

func CoalesceSymbols(tokens []*textkit.Token, clusters []string) []*textkit.Token

Types

type Grammar

type Grammar struct {
	// The rules of the grammar.
	Rules []*Rule
	// contains filtered or unexported fields
}

A formal grammar.

func NewGrammar

func NewGrammar(rules ...[]*Rule) *Grammar

Returns a new grammar.

func (*Grammar) BuildItems

func (gr *Grammar) BuildItems()

Builds the items of the automaton.

func (*Grammar) Parse

func (gr *Grammar) Parse(tokens []*textkit.Token) (interface{}, error)

Parses a list of tokens.

type Item

type Item struct {
	Lhs    string
	Rhs    []string
	DotPos int
}

An item of the parser.

func (*Item) String

func (it *Item) String() string

type Operator

type Operator struct {
	Associativity OperatorAssociativity
	Priority      int
	Symbols       []string
}

func (Operator) Name

func (op Operator) Name() string

type OperatorAssociativity

type OperatorAssociativity int
const (
	LeftAssociative OperatorAssociativity = iota
	RightAssociative
	NonAssociative
)

type Rule

type Rule struct {
	Lhs  string
	Rhs  []string
	Conv func([]interface{}) interface{}
}

A context-free rule with a builder function.

func BuildListRules

func BuildListRules(root, leaf string, canBeEmpty bool, leftBracket, sep, rightBracket string, builder func([]interface{}) interface{}) []*Rule

func BuildOperatorRules

func BuildOperatorRules(root, leaf string, ops []Operator, builder func(string, interface{}, interface{}) interface{}) []*Rule

func BuildOptSeq

func BuildOptSeq(root string, head, tail []string, builder func([]interface{}, []interface{}) interface{}) []*Rule

func (*Rule) String

func (r *Rule) String() string

Returns a string representation of the rule.

type State

type State struct {
	Items []*Item
}

A state of the parser.

func (*State) String

func (st *State) String() string

Jump to

Keyboard shortcuts

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