lalr

package
v0.0.0-...-e9866e7 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Copyright (c) 2021 Ke Yuchang(aceking.ke@gmail.com). All rights reserved. Use of this source code is governed by MIT license that can be found in the LICENSE file.

Copyright (c) 2021 Ke Yuchang(aceking.ke@gmail.com). All rights reserved. Use of this source code is governed by MIT license that can be found in the LICENSE file.

Copyright (c) 2021 Ke Yuchang(aceking.ke@gmail.com). All rights reserved. Use of this source code is governed by MIT license that can be found in the LICENSE file.

Copyright (c) 2021 Ke Yuchang(aceking.ke@gmail.com). All rights reserved. Use of this source code is governed by MIT license that can be found in the LICENSE file.

Copyright (c) 2021 Ke Yuchang(aceking.ke@gmail.com). All rights reserved. Use of this source code is governed by MIT license that can be found in the LICENSE file.

Copyright (c) 2021 Ke Yuchang(aceking.ke@gmail.com). All rights reserved. Use of this source code is governed by MIT license that can be found in the LICENSE file.

Index

Constants

View Source
const (
	MaxInt  = 1<<(UintSize-1) - 1 // 1<<31 - 1 or 1<<63 - 1
	MinInt  = -MaxInt - 1         // -1 << 31 or -1 << 63
	MaxUint = 1<<UintSize - 1     // 1<<32 - 1 or 1<<64 - 1

	Mask      = ^(uint(1) << 32)
	CheckMask = (uint(1) << 32)
)
View Source
const UintSize = 32 << (^uint(0) >> 32 & 1) // 32 or 64

Variables

This section is empty.

Functions

func Digraph

func Digraph(X []int, R []Relation,
	Fp map[int][]int, F *map[int][]int)

func Traverse

func Traverse(x int, R []Relation,
	FP map[int][]int, F *map[int][]int,
	N map[int]int, S *stack)

func Union

func Union(a []int, b []int) []int

Types

type Action

type Action struct {
	Sym         *symbol.Symbol
	ActionType  E_ActionType
	ActionIndex int
	PrecType    symbol.E_Precedence
	Prec        int
}

type E_ActionType

type E_ActionType int
const (
	SHIFT E_ActionType = iota
	REDUCE
	ERROR
	SHIFT_REDUCE_CONFLICT
	REDUCE_REDUCE_CONFLICT
)

type LALR1

type LALR1 struct {
	G *grammar.Grammar

	GTable [][]int
	DRSet,
	ReadSet,
	FollowSet,
	LookAheadSet map[int][]int
	NumOfStates int //States number
	// The last is for pack table
	NeedPacked  bool
	ActionTable []int
	OffsetTable []int
	CheckTable  []int
	ActionDef   []int
	GoToDef     []int
	// contains filtered or unexported fields
}

func ComputeLALR

func ComputeLALR(g *grammar.Grammar) *LALR1

func NewLALR

func NewLALR(g *grammar.Grammar) *LALR1

NewLALR

func (*LALR1) BuildTrans

func (lalr *LALR1) BuildTrans()

func (*LALR1) CaclIncludeRelation

func (lalr *LALR1) CaclIncludeRelation(tr int) []Relation

-----------------Caculate the Includes relation------------- B-> beta A gama if gama can episilon, p' --- beta --> p (p, A) includes (p', B)

calculate the include Relation.

func (*LALR1) CaclIncludes

func (lalr *LALR1) CaclIncludes() []Relation

calc all the relation

func (*LALR1) CalcAllReadRelations

func (lalr *LALR1) CalcAllReadRelations() []Relation

func calc all reads relations

func (*LALR1) CalcDR

func (lalr *LALR1) CalcDR()

calc the DR

func (*LALR1) CalcFollowSet

func (lalr *LALR1) CalcFollowSet()

calc the follow set

func (*LALR1) CalcLookAheadSet

func (lalr *LALR1) CalcLookAheadSet()

calc the look ahead Set

func (*LALR1) CalcLookbacks

func (lalr *LALR1) CalcLookbacks() []Relation

calculate lookback relation

func (*LALR1) CalcReadSet

func (lalr *LALR1) CalcReadSet()

calculate the Reads Set

func (*LALR1) CheckAndResolveConflict

func (lalr *LALR1) CheckAndResolveConflict(state int, tranlist []Transistor) (map[int][]*Action, error)

check weath it has shift/reduce conflict or reduce/reduce conflict

func (*LALR1) DrawGrammar

func (lalr *LALR1) DrawGrammar(tab [][]int) *gographviz.Graph

func (*LALR1) GenAcceptCode

func (lalr *LALR1) GenAcceptCode() int

Get the accept action code

func (*LALR1) GenErrorCode

func (lalr *LALR1) GenErrorCode() int

Get the error action code Max State + 100 is the error

func (*LALR1) GenTable

func (lalr *LALR1) GenTable() ([][]int, error)

generate Table

func (*LALR1) ResolveConflict

func (lalr *LALR1) ResolveConflict(act01, act02 *Action) (*Action, error)

Resolve the conflict by Prec

func (*LALR1) ShowAndCheckConflict

func (lalr *LALR1) ShowAndCheckConflict(state int, tranlist []Transistor)

func (*LALR1) ShowDrSet

func (lalr *LALR1) ShowDrSet()

show Dr set

func (*LALR1) ShowFollowSet

func (lalr *LALR1) ShowFollowSet()

func (*LALR1) ShowIncludes

func (lalr *LALR1) ShowIncludes(R Relation)

Show the includes

func (*LALR1) ShowLookAheadSet

func (lalr *LALR1) ShowLookAheadSet()

Show the LookAheadSet

func (*LALR1) ShowLookbacks

func (lalr *LALR1) ShowLookbacks(R Relation)

Show the lookbacks

func (*LALR1) ShowReadSet

func (lalr *LALR1) ShowReadSet()

func (*LALR1) ShowReads

func (lalr *LALR1) ShowReads(R Relation)

func (*LALR1) SplitActionAndGotoTable

func (lalr *LALR1) SplitActionAndGotoTable(tab [][]int) ([][]int, [][]int)

func (*LALR1) TryPackedTable

func (lalr *LALR1) TryPackedTable(tab [][]int) error

the table is packed

func (*LALR1) TrySplitTable

func (lalr *LALR1) TrySplitTable(tab [][]int) error

Try to split the table, and pack it

func (*LALR1) UseDefaultResolveConflict

func (lalr *LALR1) UseDefaultResolveConflict(act01, act02 *Action) *Action

resolve with default method shift/reduce , resolve it with shift reduce/reduce , resolve it with rule which is first defined

type Relation

type Relation struct {
	Index int
	// contains filtered or unexported fields
}

type Transistor

type Transistor struct {
	Index int
	// contains filtered or unexported fields
}

q --t--> p

Jump to

Keyboard shortcuts

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