parser

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NUM_STATES = 120
	NUM_TOKENS = 22
)
View Source
const (
	NT_Grammar          = 0
	NT_LexicalPart      = 1
	NT_LexProductions   = 2
	NT_LexProduction    = 3
	NT_LexPattern       = 4
	NT_LexAlt           = 5
	NT_LexTerm          = 6
	NT_SyntaxPart       = 7
	NT_SyntaxProdList   = 8
	NT_SyntaxProduction = 9
	NT_Alternatives     = 10
	NT_SyntaxBody       = 11
	NT_Symbols          = 12
	NT_Symbol           = 13
	NT_FileHeader       = 14
)
View Source
const INITIAL_STACK_SIZE = 100
View Source
const (
	NUM_NT = 15
)

NUM_NT is the set of non-terminal symbols of the target grammar.

View Source
const NUM_PRODS = 40

Variables

View Source
var ProductionsTable = ProdTab{

	ProdTabEntry{
		"S! : Grammar ;",
		"S!",
		1,
		func(X []Attrib) (Attrib, error) {
			return X[0], nil
		},
	},

	ProdTabEntry{
		"Grammar : LexicalPart SyntaxPart << ast.NewGrammar(X[0], X[1]) >> ;",
		"Grammar",
		2,
		func(X []Attrib) (Attrib, error) {
			return ast.NewGrammar(X[0], X[1])
		},
	},

	ProdTabEntry{
		"Grammar : LexicalPart << ast.NewGrammar(X[0], nil) >> ;",
		"Grammar",
		1,
		func(X []Attrib) (Attrib, error) {
			return ast.NewGrammar(X[0], nil)
		},
	},

	ProdTabEntry{
		"Grammar : SyntaxPart << ast.NewGrammar(nil, X[0]) >> ;",
		"Grammar",
		1,
		func(X []Attrib) (Attrib, error) {
			return ast.NewGrammar(nil, X[0])
		},
	},

	ProdTabEntry{
		"LexicalPart : LexProductions << ast.NewLexPart(nil, nil, X[0]) >> ;",
		"LexicalPart",
		1,
		func(X []Attrib) (Attrib, error) {
			return ast.NewLexPart(nil, nil, X[0])
		},
	},

	ProdTabEntry{
		"LexProductions : LexProduction << ast.NewLexProductions(X[0]) >> ;",
		"LexProductions",
		1,
		func(X []Attrib) (Attrib, error) {
			return ast.NewLexProductions(X[0])
		},
	},

	ProdTabEntry{
		"LexProductions : LexProductions LexProduction << ast.AppendLexProduction(X[0], X[1]) >> ;",
		"LexProductions",
		2,
		func(X []Attrib) (Attrib, error) {
			return ast.AppendLexProduction(X[0], X[1])
		},
	},

	ProdTabEntry{
		"LexProduction : tokId : LexPattern ; << ast.NewLexTokDef(X[0], X[2]) >> ;",
		"LexProduction",
		4,
		func(X []Attrib) (Attrib, error) {
			return ast.NewLexTokDef(X[0], X[2])
		},
	},

	ProdTabEntry{
		"LexProduction : regDefId : LexPattern ; << ast.NewLexRegDef(X[0], X[2]) >> ;",
		"LexProduction",
		4,
		func(X []Attrib) (Attrib, error) {
			return ast.NewLexRegDef(X[0], X[2])
		},
	},

	ProdTabEntry{
		"LexProduction : ignoredTokId : LexPattern ; << ast.NewLexIgnoredTokDef(X[0], X[2]) >> ;",
		"LexProduction",
		4,
		func(X []Attrib) (Attrib, error) {
			return ast.NewLexIgnoredTokDef(X[0], X[2])
		},
	},

	ProdTabEntry{
		"LexPattern : LexAlt << ast.NewLexPattern(X[0]) >> ;",
		"LexPattern",
		1,
		func(X []Attrib) (Attrib, error) {
			return ast.NewLexPattern(X[0])
		},
	},

	ProdTabEntry{
		"LexPattern : LexPattern | LexAlt << ast.AppendLexAlt(X[0], X[2]) >> ;",
		"LexPattern",
		3,
		func(X []Attrib) (Attrib, error) {
			return ast.AppendLexAlt(X[0], X[2])
		},
	},

	ProdTabEntry{
		"LexAlt : LexTerm << ast.NewLexAlt(X[0]) >> ;",
		"LexAlt",
		1,
		func(X []Attrib) (Attrib, error) {
			return ast.NewLexAlt(X[0])
		},
	},

	ProdTabEntry{
		"LexAlt : LexAlt LexTerm << ast.AppendLexTerm(X[0], X[1]) >> ;",
		"LexAlt",
		2,
		func(X []Attrib) (Attrib, error) {
			return ast.AppendLexTerm(X[0], X[1])
		},
	},

	ProdTabEntry{
		"LexTerm : . << ast.LexDOT, nil >> ;",
		"LexTerm",
		1,
		func(X []Attrib) (Attrib, error) {
			return ast.LexDOT, nil
		},
	},

	ProdTabEntry{
		"LexTerm : char_lit << ast.NewLexCharLit(X[0]) >> ;",
		"LexTerm",
		1,
		func(X []Attrib) (Attrib, error) {
			return ast.NewLexCharLit(X[0])
		},
	},

	ProdTabEntry{
		"LexTerm : char_lit - char_lit << ast.NewLexCharRange(X[0], X[2]) >> ;",
		"LexTerm",
		3,
		func(X []Attrib) (Attrib, error) {
			return ast.NewLexCharRange(X[0], X[2])
		},
	},

	ProdTabEntry{
		"LexTerm : regDefId << ast.NewLexRegDefId(X[0]) >> ;",
		"LexTerm",
		1,
		func(X []Attrib) (Attrib, error) {
			return ast.NewLexRegDefId(X[0])
		},
	},

	ProdTabEntry{
		"LexTerm : [ LexPattern ] << ast.NewLexOptPattern(X[1]) >> ;",
		"LexTerm",
		3,
		func(X []Attrib) (Attrib, error) {
			return ast.NewLexOptPattern(X[1])
		},
	},

	ProdTabEntry{
		"LexTerm : { LexPattern } << ast.NewLexRepPattern(X[1]) >> ;",
		"LexTerm",
		3,
		func(X []Attrib) (Attrib, error) {
			return ast.NewLexRepPattern(X[1])
		},
	},

	ProdTabEntry{
		"LexTerm : ( LexPattern ) << ast.NewLexGroupPattern(X[1]) >> ;",
		"LexTerm",
		3,
		func(X []Attrib) (Attrib, error) {
			return ast.NewLexGroupPattern(X[1])
		},
	},

	ProdTabEntry{
		"SyntaxPart : FileHeader SyntaxProdList << ast.NewSyntaxPart(X[0], X[1]) >> ;",
		"SyntaxPart",
		2,
		func(X []Attrib) (Attrib, error) {
			return ast.NewSyntaxPart(X[0], X[1])
		},
	},

	ProdTabEntry{
		"SyntaxPart : SyntaxProdList << ast.NewSyntaxPart(nil, X[0]) >> ;",
		"SyntaxPart",
		1,
		func(X []Attrib) (Attrib, error) {
			return ast.NewSyntaxPart(nil, X[0])
		},
	},

	ProdTabEntry{
		"SyntaxProdList : SyntaxProduction << ast.NewSyntaxProdList(X[0]) >> ;",
		"SyntaxProdList",
		1,
		func(X []Attrib) (Attrib, error) {
			return ast.NewSyntaxProdList(X[0])
		},
	},

	ProdTabEntry{
		"SyntaxProdList : SyntaxProdList SyntaxProduction << ast.AddSyntaxProds(X[0], X[1]) >> ;",
		"SyntaxProdList",
		2,
		func(X []Attrib) (Attrib, error) {
			return ast.AddSyntaxProds(X[0], X[1])
		},
	},

	ProdTabEntry{
		"SyntaxProduction : prodId : Alternatives ; << ast.NewSyntaxProd(X[0], X[2]) >> ;",
		"SyntaxProduction",
		4,
		func(X []Attrib) (Attrib, error) {
			return ast.NewSyntaxProd(X[0], X[2])
		},
	},

	ProdTabEntry{
		"Alternatives : SyntaxBody << ast.NewSyntaxAlts(X[0]) >> ;",
		"Alternatives",
		1,
		func(X []Attrib) (Attrib, error) {
			return ast.NewSyntaxAlts(X[0])
		},
	},

	ProdTabEntry{
		"Alternatives : Alternatives | SyntaxBody << ast.AddSyntaxAlt(X[0], X[2]) >> ;",
		"Alternatives",
		3,
		func(X []Attrib) (Attrib, error) {
			return ast.AddSyntaxAlt(X[0], X[2])
		},
	},

	ProdTabEntry{
		"SyntaxBody : Symbols << ast.NewSyntaxBody(X[0], nil) >> ;",
		"SyntaxBody",
		1,
		func(X []Attrib) (Attrib, error) {
			return ast.NewSyntaxBody(X[0], nil)
		},
	},

	ProdTabEntry{
		"SyntaxBody : Symbols g_sdt_lit << ast.NewSyntaxBody(X[0], X[1]) >> ;",
		"SyntaxBody",
		2,
		func(X []Attrib) (Attrib, error) {
			return ast.NewSyntaxBody(X[0], X[1])
		},
	},

	ProdTabEntry{
		"SyntaxBody : error << ast.NewErrorBody(nil, nil) >> ;",
		"SyntaxBody",
		1,
		func(X []Attrib) (Attrib, error) {
			return ast.NewErrorBody(nil, nil)
		},
	},

	ProdTabEntry{
		"SyntaxBody : error Symbols << ast.NewErrorBody(X[1], nil) >> ;",
		"SyntaxBody",
		2,
		func(X []Attrib) (Attrib, error) {
			return ast.NewErrorBody(X[1], nil)
		},
	},

	ProdTabEntry{
		"SyntaxBody : error Symbols g_sdt_lit << ast.NewErrorBody(X[1], X[2]) >> ;",
		"SyntaxBody",
		3,
		func(X []Attrib) (Attrib, error) {
			return ast.NewErrorBody(X[1], X[2])
		},
	},

	ProdTabEntry{
		"SyntaxBody : empty << ast.NewEmptyBody() >> ;",
		"SyntaxBody",
		1,
		func(X []Attrib) (Attrib, error) {
			return ast.NewEmptyBody()
		},
	},

	ProdTabEntry{
		"Symbols : Symbol << ast.NewSyntaxSymbols(X[0]) >> ;",
		"Symbols",
		1,
		func(X []Attrib) (Attrib, error) {
			return ast.NewSyntaxSymbols(X[0])
		},
	},

	ProdTabEntry{
		"Symbols : Symbols Symbol << ast.AddSyntaxSymbol(X[0], X[1]) >> ;",
		"Symbols",
		2,
		func(X []Attrib) (Attrib, error) {
			return ast.AddSyntaxSymbol(X[0], X[1])
		},
	},

	ProdTabEntry{
		"Symbol : prodId << ast.NewSyntaxProdId(X[0]) >> ;",
		"Symbol",
		1,
		func(X []Attrib) (Attrib, error) {
			return ast.NewSyntaxProdId(X[0])
		},
	},

	ProdTabEntry{
		"Symbol : tokId << ast.NewTokId(X[0]) >> ;",
		"Symbol",
		1,
		func(X []Attrib) (Attrib, error) {
			return ast.NewTokId(X[0])
		},
	},

	ProdTabEntry{
		"Symbol : string_lit << ast.NewStringLit(X[0]) >> ;",
		"Symbol",
		1,
		func(X []Attrib) (Attrib, error) {
			return ast.NewStringLit(X[0])
		},
	},

	ProdTabEntry{
		"FileHeader : g_sdt_lit << ast.NewFileHeader(X[0]) >> ;",
		"FileHeader",
		1,
		func(X []Attrib) (Attrib, error) {
			return ast.NewFileHeader(X[0])
		},
	},
}

Functions

func Acc

func Acc()

func NewStack

func NewStack() *stack

Types

type Accept

type Accept int

func (Accept) Act

func (this Accept) Act()

func (Accept) Equal

func (this Accept) Equal(that Action) bool

func (Accept) String

func (this Accept) String() string

type Action

type Action interface {
	Act()
	String() string
}

type ActionRow

type ActionRow struct {
	Actions Actions
	// contains filtered or unexported fields
}

func (*ActionRow) String

func (R *ActionRow) String() string

type ActionRowU

type ActionRowU [NUM_TOKENS]Action

type ActionTab

type ActionTab []*ActionRow
var ActionTable ActionTab = ActionTab{}/* 120 elements not displayed */

type ActionTabU

type ActionTabU [NUM_STATES]ActionRowU

type Actions

type Actions map[token.Type]Action

type Attrib

type Attrib interface {
}

type CanRecover

type CanRecover [NUM_STATES]bool

type GotoRow

type GotoRow map[NT]State

type GotoRowU

type GotoRowU [NUM_NT]State

type GotoTab

type GotoTab []GotoRow
var GotoTable GotoTab = GotoTab{}/* 120 elements not displayed */

type GotoTabU

type GotoTabU [NUM_STATES]GotoRowU

type NT

type NT string

type Parser

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

func NewParser

func NewParser(act ActionTab, gto GotoTab, prod ProdTab, tm *token.TokenMap) *Parser

func (*Parser) Error

func (P *Parser) Error(err error, scanner Scanner) (recovered bool, errorAttrib *errs.Error)

func (*Parser) Parse

func (this *Parser) Parse(scanner Scanner) (res interface{}, err error)

func (*Parser) Reset

func (P *Parser) Reset()

func (*Parser) TokString

func (P *Parser) TokString(tok *token.Token) string

type ParserUTab

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

func NewParserUTab

func NewParserUTab(tm *token.TokenMap) *ParserUTab

func (*ParserUTab) Error

func (P *ParserUTab) Error(err error, scanner Scanner) (recovered bool, errorAttrib *errs.Error)

func (*ParserUTab) Parse

func (this *ParserUTab) Parse(scanner Scanner) (res interface{}, err error)

func (*ParserUTab) Reset

func (P *ParserUTab) Reset()

func (*ParserUTab) TokString

func (P *ParserUTab) TokString(tok *token.Token) string

type ProdTab

type ProdTab []ProdTabEntry

type ProdTabEntry

type ProdTabEntry struct {
	String     string
	Head       NT
	NumSymbols int
	ReduceFunc func([]Attrib) (Attrib, error)
}

type ProdTabU

type ProdTabU [NUM_PRODS]*ProdTabUEntry

type ProdTabUEntry

type ProdTabUEntry struct {
	String     string
	Head       NT
	HeadIndex  int
	NumSymbols int
	ReduceFunc func([]Attrib) (Attrib, error)
}

type Reduce

type Reduce int

func (Reduce) Act

func (this Reduce) Act()

func (Reduce) Equal

func (this Reduce) Equal(that Action) bool

func (Reduce) String

func (this Reduce) String() string

type Scanner

type Scanner interface {
	Scan() (*token.Token, token.Position)
}

type Shift

type Shift State

func (Shift) Act

func (this Shift) Act()

func (Shift) Equal

func (this Shift) Equal(that Action) bool

func (Shift) String

func (this Shift) String() string

type State

type State int

Jump to

Keyboard shortcuts

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