bsr

package
v0.0.0-...-d977049 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package bsr implements a Binary Subtree Representation set as defined in

Scott et al
Derivation representation using binary subtree sets,
Science of Computer Programming 175 (2019)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BSR

type BSR struct {
	Label slot.Label
	// contains filtered or unexported fields
}

BSR is the binary subtree representation of a parsed nonterminal

func (BSR) Alternate

func (b BSR) Alternate() int

Alternate returns the index of the grammar rule alternate.

func (BSR) GetAllNTChildren

func (b BSR) GetAllNTChildren() [][]BSR

GetAllNTChildren returns all the NT Children of b. If an NT child of b has ambiguous parses then all parses of that child are returned.

func (BSR) GetNTChild

func (b BSR) GetNTChild(nt symbols.NT, i int) BSR

GetNTChild returns the BSR of occurrence i of nt in s. GetNTChild fails if s has ambiguous subtrees of occurrence i of nt.

func (BSR) GetNTChildI

func (b BSR) GetNTChildI(i int) BSR

GetNTChildI returns the BSR of NT symbol[i] in the BSR set. GetNTChildI fails if the BSR set has ambiguous subtrees of NT i.

func (BSR) GetNTChildren

func (b BSR) GetNTChildren(nt symbols.NT, i int) []BSR

GetNTChildren returns all the BSRs of occurrence i of nt in s

func (BSR) GetNTChildrenI

func (b BSR) GetNTChildrenI(i int) []BSR

GetNTChildrenI returns all the BSRs of NT symbol[i] in s

func (BSR) GetTChildI

func (b BSR) GetTChildI(i int) *token.Token

GetTChildI returns the terminal symbol at position i in b. GetTChildI panics if symbol i is not a valid terminal

func (BSR) LeftExtent

func (b BSR) LeftExtent() int

LeftExtent returns the left extent of the BSR

func (BSR) Pivot

func (b BSR) Pivot() int

Pivot returns the pivot of the BSR

func (BSR) RightExtent

func (b BSR) RightExtent() int

RightExtent returns the right extent of the BSR

func (BSR) String

func (b BSR) String() string

type Set

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

Set contains the set of Binary Subtree Representations (BSR).

func New

func New(startSymbol symbols.NT, l *lexer.Lexer) *Set

New returns a new initialised BSR Set

func (*Set) Add

func (s *Set) Add(l slot.Label, i, k, j int)

Add a bsr to the set. (i,j) is the extent. k is the pivot.

func (*Set) AddEmpty

func (s *Set) AddEmpty(l slot.Label, i int)

AddEmpty adds a grammar slot: X : ϵ•

func (*Set) Contain

func (s *Set) Contain(nt symbols.NT, left, right int) bool

Contain returns true iff the BSR Set contains the NT symbol with left and right extent.

func (*Set) Dump

func (s *Set) Dump()

Dump prints the NT symbols of the parse forest.

func (*Set) FilterByOrderedChoice

func (s *Set) FilterByOrderedChoice()

Removes all the BSR nodes that don't match the PEG ordered choice property

func (*Set) FlatDump

func (s *Set) FlatDump()

Dumps all BSR nodes in a set, not just those reachable from roots.

func (*Set) GetAll

func (s *Set) GetAll() (bsrs []BSR)

GetAll returns all BSR grammar slot entries

func (*Set) GetRightExtent

func (s *Set) GetRightExtent() int

GetRightExtent returns the right extent of the BSR set

func (*Set) GetRoot

func (s *Set) GetRoot() BSR

GetRoot returns the root of the parse tree of an unambiguous parse. GetRoot fails if the parse was ambiguous. Use GetRoots() for ambiguous parses.

func (*Set) GetRoots

func (s *Set) GetRoots() (roots []BSR)

GetRoots returns all the roots of parse trees of the start symbol of the grammar.

func (*Set) IsAmbiguous

func (s *Set) IsAmbiguous() bool

IsAmbiguous returns true if the BSR set does not have exactly one root, or if any BSR in the set has an NT symbol, which does not have exactly one sub-tree.

func (*Set) ReportAmbiguous

func (s *Set) ReportAmbiguous()

ReportAmbiguous lists the ambiguous subtrees of the parse forest

Jump to

Keyboard shortcuts

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