lr

package
v0.0.0-...-dd1d5c9 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2023 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AcceptRule  = "#accept"
	StartMarker = "^"
	EndMarker   = "$"
	Wildcard    = "*"
)
View Source
const (
	Generic = "Generic_"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ByDeclLoc

type ByDeclLoc []*Term

func (ByDeclLoc) Len

func (list ByDeclLoc) Len() int

func (ByDeclLoc) Less

func (list ByDeclLoc) Less(i int, j int) bool

func (ByDeclLoc) Swap

func (list ByDeclLoc) Swap(i int, j int)

type ByRuleLoc

type ByRuleLoc []*Term

func (ByRuleLoc) Len

func (list ByRuleLoc) Len() int

func (ByRuleLoc) Less

func (list ByRuleLoc) Less(i int, j int) bool

func (ByRuleLoc) Swap

func (list ByRuleLoc) Swap(i int, j int)

type Clause

type Clause struct {
	SortId int // 0 (and negatives) are reserved for the start rules.
	parser.LRLocation

	Label string

	Bindings []*Term

	// Temp variable populated by the code generator.
	CodeGenReducerName      string
	CodeGenReducerNameConst string
	CodeGenReduceAction     string
}

type GoSpec

type GoSpec struct {
	Package                   string            `yaml:"package"`
	Prefix                    string            `yaml:"prefix"`
	ValueTypes                map[string]string `yaml:"value_types"`
	OutputDebugNonKernelItems bool              `yaml:"output_debug_non_kernel_items"`
}

type Grammar

type Grammar struct {
	Source string

	Terms map[string]*Term

	Terminals    []*Term // sorted by declaration location
	NonTerminals []*Term // sorted by rule location

	Starts []*Term

	*LangSpecs
}

func NewGrammar

func NewGrammar(
	sourceFile string,
	parsed *parser.Grammar) (
	*Grammar,
	error)

type Item

type Item struct {
	*Term
	*Clause

	Dot int

	LookAhead string

	IsReduce bool
	IsKernel bool

	Key  string
	Next *Item
	Core *Item

	Pool *itemPool
}

LR(1) production item of the form: A -> [a B] . [c] , x

func (*Item) Compare

func (this *Item) Compare(other *Item) int

sort order:

kernel items before non-kernel items
clause sort id
dot position
lookahead string

func (*Item) ReplaceLookAhead

func (item *Item) ReplaceLookAhead(symbol string) *Item

func (*Item) Shift

func (item *Item) Shift() *Item

func (*Item) String

func (item *Item) String() string

type ItemSet

type ItemSet struct {
	Kernel      string
	KernelItems Items // sorted
	Items             // sorted

	StateNum int

	Goto map[string]*ItemSet

	Reduce map[string]Items

	ReduceReduceConflictSymbols []string
	ShiftReduceConflictSymbols  []string

	CodeGenConst  string
	CodeGenAction string
}

type Items

type Items []*Item

func (Items) Len

func (items Items) Len() int

func (Items) Less

func (items Items) Less(iIdx int, jIdx int) bool

func (Items) String

func (items Items) String() string

func (Items) Swap

func (items Items) Swap(i int, j int)

type LRStates

type LRStates struct {
	*Grammar

	FirstTerms map[string]*firstTermsEntry

	ItemPool *itemPool

	States        map[string]*ItemSet
	OrderedStates []*ItemSet

	ShiftReduceConflictsCount  int
	ReduceReduceConflictsCount int
}

func NewLRStates

func NewLRStates(grammar *Grammar) *LRStates

type LangSpecs

type LangSpecs struct {
	Go *GoSpec `yaml:"go"`
}

type Param

type Param struct {
	Name      string
	ParamType interface{}
}

type ParamList

type ParamList []*Param

func (ParamList) Len

func (list ParamList) Len() int

func (ParamList) Less

func (list ParamList) Less(i int, j int) bool

func (ParamList) Swap

func (list ParamList) Swap(i int, j int)

type Term

type Term struct {
	Name string
	parser.LRLocation

	SymbolId parser.LRSymbolId

	IsTerminal bool

	ValueType string

	RuleLocation parser.LRLocation
	Clauses      []*Clause

	Reachable bool

	CodeGenSymbolConst string

	// Temp variable populated by code generator.  The generated type is
	// language specific.
	CodeGenType interface{}
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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