items

package
v0.0.0-...-2292f9e Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Item

type Item struct {
	ProdIdx         int             // index in list of productions in Grammar.Prod
	Prod            *ast.SyntaxProd // The syntax production of this item
	Id              string
	Body            []string
	Pos             int    // position of • in the item
	ExpectedSymbol  string // the next exptect symbol in the item, if this isn't a reduce item.
	FollowingSymbol string // The next expected symbol after the item has been recognised
	Len             int    // the number of symbols making up the body
	// contains filtered or unexported fields
}

An LR1 Item.

func NewItem

func NewItem(prodIdx int, prod *ast.SyntaxProd, pos int, followingSymbol string) *Item

following symbol: the symbol expected after this item has been reduced.

func (*Item) Equals

func (this *Item) Equals(that *Item) bool

Equals weturns whether two Items are equal based on their ProdIdx, Pos and NextToken.

func (*Item) Move

func (this *Item) Move() (next *Item)

func (*Item) String

func (this *Item) String() string

func (*Item) Symbol

func (this *Item) Symbol(i int) string

type ItemSet

type ItemSet struct {
	SetNo int

	Items []*Item
	// string: symbol, int: nextState.
	Transitions map[string]int

	Symbols *symbols.Symbols
	Prods   ast.SyntaxProdList
	FS      *first.FirstSets
	// contains filtered or unexported fields
}

func InitialItemSet

func InitialItemSet(g *ast.Grammar, symbols *symbols.Symbols, fs *first.FirstSets) *ItemSet

Returns the initial Item of a Grammar.

func NewItemSet

func NewItemSet(symbols *symbols.Symbols, prods ast.SyntaxProdList, fs *first.FirstSets) *ItemSet

NewItemSet returns a newly cosntructed set of items.

func (*ItemSet) Action

func (this *ItemSet) Action(symbol string) (act1 action.Action, conflicts []action.Action)

func (*ItemSet) AddItem

func (this *ItemSet) AddItem(items ...*Item)

func (*ItemSet) AddTransition

func (this *ItemSet) AddTransition(symbol string, nextSet int)

func (*ItemSet) CanRecover

func (this *ItemSet) CanRecover() bool

func (*ItemSet) Closure

func (this *ItemSet) Closure() (c *ItemSet)

TODO: optimise loop

Dragon book, 2nd ed, section 4.7.2, p261

Closure(I)
repeat
	for each item [A->x•By, a] in I
		for each production B -> z in G'
			for each terminal b in FIRST(ya)
				add [B -> •z, b] to I
until no more items are added to I

func (*ItemSet) Contain

func (this *ItemSet) Contain(item *Item) bool

func (*ItemSet) ContainString

func (this *ItemSet) ContainString(item string) bool

func (*ItemSet) Equal

func (this *ItemSet) Equal(that *ItemSet) bool

Equal will return whether two lists of Items are equal.

func (*ItemSet) Goto

func (I *ItemSet) Goto(X string) *ItemSet

Goto implements Dragon book, 2nd ed, section 4.7.2, p261.

func (*ItemSet) NextSetIndex

func (this *ItemSet) NextSetIndex(symbol string) int

func (*ItemSet) Size

func (this *ItemSet) Size() int

Size returns the number of items in the set.

func (*ItemSet) String

func (this *ItemSet) String() string

type ItemSets

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

A list of a list of Items.

func GetItemSets

func GetItemSets(g *ast.Grammar, s *symbols.Symbols, firstSets *first.FirstSets) *ItemSets

TODO: optimise loop g is a BNF grammar. Items returns the sets of Items of the grammar g.

func (*ItemSets) Contains

func (this *ItemSets) Contains(I *ItemSet) bool

Returns whether the list of a list of items contains the list of items.

func (*ItemSets) GetIndex

func (this *ItemSets) GetIndex(I *ItemSet) int

Returns the index of the list of items.

func (*ItemSets) List

func (this *ItemSets) List() []*ItemSet

Return a slice containing all the item sets in increasing order of index

func (*ItemSets) Set

func (this *ItemSets) Set(SetNo int) *ItemSet

return set[SetNo]

func (*ItemSets) Size

func (this *ItemSets) Size() int

Returns the number of item sets

func (*ItemSets) String

func (this *ItemSets) String() string

Returns a string representing the list of the list of items.

type RowConflicts

type RowConflicts map[string][]action.Action

key: symbol; value: list of actions.

Jump to

Keyboard shortcuts

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