type yyLexer interface {
Lex(lval *yySymType) int
+ Error(e string)
}
Lex should return the token identifier, and place other token
information in lval (which replaces the usual yylval).
+Error is equivalent to yyerror in the original yacc.
Code inside the parser may refer to the variable yylex
which holds the yyLexer passed to Parse.
type yyLexer interface {
Lex(lval *yySymType) int
+ Error(s string)
}
const yyFlag = -1000
yystack:
/* put a state and value onto the stack */
if yyDebug >= 4 {
- fmt.Printf("char %v in %v", yyTokname(yychar), yyStatname(yystate))
+ fmt.Printf("char %v in %v\n", yyTokname(yychar), yyStatname(yystate))
}
yyp++
/* error ... attempt to resume parsing */
switch Errflag {
case 0: /* brand new error */
- yyError("syntax error")
+ yylex.Error("syntax error")
Nerrs++
if yyDebug >= 1 {
fmt.Printf("%s", yyStatname(yystate))
/* reduction by production yyn */
if yyDebug >= 2 {
- fmt.Printf("reduce %v in:\n\t%v", yyn, yyStatname(yystate))
+ fmt.Printf("reduce %v in:\n\t%v\n", yyn, yyStatname(yystate))
}
yynt := yyn
type UnitsLex int
-func (l UnitsLex) Lex(yylval *yySymType) int {
+func (_ UnitsLex) Lex(yylval *yySymType) int {
var c, i int
c = peekrune
return VAL
}
+func (_ UnitsLex) Error(s string) {
+ Error("syntax error, last name: %v", sym)
+}
+
func main() {
var file string
return false
}
-func yyError(s string) {
- Error("syntax error, last name: %v", sym)
-}
-
func Error(s string, v ...interface{}) {
fmt.Printf("%v: %v\n\t", lineno, line)
fmt.Printf(s, v)