diff options
| author | Ryo Nihei <nihei.dev@gmail.com> | 2022-11-06 21:31:46 +0900 |
|---|---|---|
| committer | Ryo Nihei <nihei.dev@gmail.com> | 2022-11-10 00:40:16 +0900 |
| commit | f89d021bbe134e3efa0d015a41e9712960cdd009 (patch) | |
| tree | 28c6d49611f09dad186b0f6fc4c1a42864a2f7cb /grammar/item.go | |
| parent | Split SymbolTable's APIs into reader/writer (diff) | |
| download | urubu-f89d021bbe134e3efa0d015a41e9712960cdd009.tar.gz urubu-f89d021bbe134e3efa0d015a41e9712960cdd009.tar.xz | |
Import source code of lexer generator
From: https://github.com/nihei9/maleeni
Diffstat (limited to 'grammar/item.go')
| -rw-r--r-- | grammar/item.go | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/grammar/item.go b/grammar/item.go index 100d920..84c4911 100644 --- a/grammar/item.go +++ b/grammar/item.go @@ -6,6 +6,8 @@ import ( "fmt" "sort" "strconv" + + "github.com/nihei9/vartan/grammar/symbol" ) type lrItemID [32]byte @@ -19,7 +21,7 @@ func (id lrItemID) num() uint32 { } type lookAhead struct { - symbols map[symbol]struct{} + symbols map[symbol.Symbol]struct{} // When propagation is true, an item propagates look-ahead symbols to other items. propagation bool @@ -38,7 +40,7 @@ type lrItem struct { // 2 | T | E → E +・T // 3 | Nil | E → E + T・ dot int - dottedSymbol symbol + dottedSymbol symbol.Symbol // When initial is true, the LHS of the production is the augmented start symbol and dot is 0. // It looks like S' →・S. @@ -74,13 +76,13 @@ func newLR0Item(prod *production, dot int) (*lrItem, error) { id = sha256.Sum256(b) } - dottedSymbol := symbolNil + dottedSymbol := symbol.SymbolNil if dot < prod.rhsLen { dottedSymbol = prod.rhs[dot] } initial := false - if prod.lhs.isStart() && dot == 0 { + if prod.lhs.IsStart() && dot == 0 { initial = true } @@ -176,7 +178,7 @@ func (n stateNum) next() stateNum { type lrState struct { *kernel num stateNum - next map[symbol]kernelID + next map[symbol.Symbol]kernelID reducible map[productionID]struct{} // emptyProdItems stores items that have an empty production like `p → ε` and is reducible. |
