Skip to content

Commit

Permalink
*: fix the bug for eof token
Browse files Browse the repository at this point in the history
  • Loading branch information
keyuchang committed Mar 29, 2022
1 parent 68d53fc commit 1ff30a5
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Builder/GoGenCode.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func Parser(input string) *ValType {
s := &StateSymStack[StackPointer-1]
a := s.Action(lookAhead)
if a == ERROR_ACTION {
panic("Grammer error")
panic("Grammar parse error")
} else if a == ACCEPT_ACTION {
return &s.ValType
} else {
Expand Down
3 changes: 3 additions & 0 deletions Parser/Lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ func rootState(l *lexer) stateFn {
l.backup()
l.acceptRun("0123456789")
l.emit(Number)
case r == '-':
l.acceptRun("0123456789")
l.emit(Number)
case r == '{':
return ActionQuoteState

Expand Down
3 changes: 3 additions & 0 deletions Parser/Vistor.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ func (w *Walker) BuildLALR1() *lalr.LALR1 {
//1. create symbo
index := 1
for _, id := range v.idsymtabl {
if id.Value == -1 {
continue
}
index++
sy := symbol.NewSymbol(uint(index), id.Name)
sy.SetValue(id.Value)
Expand Down
1 change: 1 addition & 0 deletions examples/e.y
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import "fmt"
%}

%token 'n'
%token EOF -1
%start L
%%
L : /*empty*/
Expand Down

0 comments on commit 1ff30a5

Please sign in to comment.