Skip to content

Commit

Permalink
change error action is 0,accept as 100+maxstate
Browse files Browse the repository at this point in the history
  • Loading branch information
keyuchang committed Feb 8, 2022
1 parent 79e2ea9 commit 816ab35
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Builder/GoGenCode.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (b *GoBuilder) buildConstPart() {
b.ConstPart += fmt.Sprintf("const %s = %d\n", identifier.Name, identifier.Value)
}
}
b.ConstPart += fmt.Sprintf("const ERROR_ACTION = %d\nconst ACCEPT_ACTION = 0\n", b.vnode.GenErrorCode())
b.ConstPart += fmt.Sprintf("const ERROR_ACTION = 0\nconst ACCEPT_ACTION = %d\n", b.vnode.GenAcceptCode())
}

func (b *GoBuilder) buildUionAndCode() {
Expand Down
2 changes: 1 addition & 1 deletion Builder/TsGenCode.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (b *TsBuilder) buildConstPart() {
b.ConstPart += fmt.Sprintf("const %s = %d\n", identifier.Name, identifier.Value)
}
}
b.ConstPart += fmt.Sprintf("const ERROR_ACTION = %d\nconst ACCEPT_ACTION = 0\n", b.vnode.GenErrorCode())
b.ConstPart += fmt.Sprintf("const ERROR_ACTION = 0 \nconst ACCEPT_ACTION = %d\n", b.vnode.GenAcceptCode())
}

func (b *TsBuilder) buildUionAndCode() {
Expand Down
8 changes: 6 additions & 2 deletions LALR/Table.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,14 @@ func (lalr *LALR1) GenTable() ([][]int, error) {
} else {
row := make([]int, len(lalr.G.Symbols))
for i := 0; i < len(row); i++ {
row[i] = lalr.GenErrorCode()
row[i] = 0
}
for syInd, act := range set {
row[syInd] = act[0].ActionIndex
if act[0].ActionIndex != 0 {
row[syInd] = act[0].ActionIndex
} else {
row[syInd] = lalr.GenAcceptCode()
}
}
tableGen = append(tableGen, row)
}
Expand Down
2 changes: 1 addition & 1 deletion LALR/Utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,6 @@ func (lalr *LALR1) ShowLookAheadSet() {

// Get the error action code
// Max State + 100 is the error
func (lalr *LALR1) GenErrorCode() int {
func (lalr *LALR1) GenAcceptCode() int {
return len(lalr.G.LR0.LR0Closure) + 100
}

0 comments on commit 816ab35

Please sign in to comment.