Documentation
¶
Index ¶
- func FormatProduction(symbols []Symbol, dotIndex int) string
- type Grammar
- func (g *Grammar) EOFSymbol() Symbol
- func (g *Grammar) GetFirstSet(symbol Symbol) mapset.Set[Symbol]
- func (g *Grammar) GetProductionIndices(symbol Symbol) []int
- func (g *Grammar) GetProductions(nonTerminal Symbol) []Production
- func (g *Grammar) IsNonTerminal(symbol Symbol) bool
- func (g *Grammar) IsTerminal(symbol Symbol) bool
- func (g *Grammar) NonTerminals() []Symbol
- func (g *Grammar) Productions() []Production
- func (g *Grammar) ProgramSymbol() Symbol
- func (g *Grammar) String() string
- func (g *Grammar) Terminals() []Symbol
- type Production
- type ProductionLine
- type Symbol
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatProduction ¶
Types ¶
type Grammar ¶
type Grammar struct {
// contains filtered or unexported fields
}
func New ¶
func New(productions []Production) *Grammar
New constructs a grammar from the given productions. The first production is special, namely, the head symbol (aka the left most symbol) of the first production is considered to be the special 'program' symbol that is the topmost non-terminal; the last symbol of the first production is considered to be the special 'eof' symbol that indicates the end of input (aka the last token). If in doubt, use the production 'program -> S eof' as the first production, and as second production define 'S' and then all the subsequent productions. For example:
program -> S eof S -> ... A -> ... ...
func NewSimple ¶
func NewSimple(productionLines []ProductionLine) (*Grammar, error)
NewSimple is a convenience function that parses each production from a textual representation, and then constructs a grammar using 'New'. It's important to notice that the first production is special. See 'New' for more details. For example:
program -> S eof S -> ... A -> ... ...
func (*Grammar) GetProductionIndices ¶
func (*Grammar) GetProductions ¶
func (g *Grammar) GetProductions(nonTerminal Symbol) []Production
GetProductions returns the productions for the given non-Terminal symbol.
func (*Grammar) IsNonTerminal ¶
func (*Grammar) IsTerminal ¶
func (*Grammar) NonTerminals ¶
func (*Grammar) Productions ¶
func (g *Grammar) Productions() []Production
func (*Grammar) ProgramSymbol ¶
Returns the special "program" symbol, which is the non-Terminal symbol of the first production.
type Production ¶
func (Production) String ¶
func (p Production) String() string