A cordial greeting.
I'm learning yacc in golang and i created this file:
%{
package main
import (
"fmt"
)
%}
%union{
ex string
}
%token <ex> DB OTHER_DB
%%
query: other
|
db
;
db: DB
{
fmt.Printf("\tDB: %s\n", $1 )
}
;
other: OTHER_DB
{
fmt.Printf("\tOTHER_DB: %s\n", $1 )
}
;
%%
type mlex struct {
expr string
result int
}
func (f *mlex) Lex(lval *yySymType) int {
yyErrorVerbose = true
return 0
}
func (f *mlex) Error(s string) {
fmt.Printf("syntax error: %s\n", s)
}
func Parse(expr string) int {
m := &mlex{expr, 0}
yyParse(m)
return m.result
}
but when executing it I get this error:
syntax error: syntax error: unexpected $end, expecting DB or OTHER_DB
I have been testing this yacc file with this code:
package main
import (
"fmt"
)
func main() {
res := Parse("db")
fmt.Println(res)
}
What could it be ? Will I need anything else in the yacc file?
I am trying to make a very simple, fully functional example to understand it well.
Thanks for your time.