[plt-scheme] Getting good shift/reduce error messages using parser-tools?

From: Danny Yoo (dyoo at hkn.eecs.berkeley.edu)
Date: Mon Dec 4 19:34:55 EST 2006

Hi everyone,

I'm playing with the parser-tools for project that I'm doing just for fun, 
and I ran across a shift/reduce conflict.  Fortunately, I know exactly 
where my grammar problem is.  Unfortunately, I don't know the parser-tool 
collection well enough yet to have it give useful hints on where to find 
the error.

Here's my silly parser so far:

(module test mzscheme

   (require (lib "lex.ss" "parser-tools")
            (lib "yacc.ss" "parser-tools"))

   (define-tokens tokens (lparen atom rparen comma eof
                                 plus minus times div))

   (define parse-expression
      (tokens tokens)
      (start expr)
      (end eof)
       [expr ((expr plus expr) 'ok)])
      (error (lambda (token-ok token-name token-value start-pos end-pos)
               (raise-syntax-error #f "while consuming" token-value))))))

When I compiled this, I got an error message '1 shift/reduce conflicts'. I 
expected this: I understand the issue about forcing left precendence, so I 
can fix the problem pretty quickly.

My concern, though, is that the error message I got from the parser-tools 
is minimal: it doesn't given any location information to pinpoint which 
rule I should paying attention to.  If my grammar were larger and more 
complex, I'd be a bit unhappy about the sparse error message.

Is there something in the tool that I have to turn on to get extended 
diagnostic information?  I'm thinking I could just dump it to yacc format 
and ask yacc to give me better information, but that seems slightly silly.


Posted on the users mailing list.