0

If a syntax error is detected by Yacc and verbose errors is defined, an error message is printed, for example

unexpected '[', expecting BECOMES

Is there a way to replace the token name for multi-character tokens (e.g. BECOMES) with the actual string (e.g. :=) in the error message? The reason I'm asking is that it may not be obvious to the user of the parser that BECOMES stand for :=.

August Karlstrom
  • 10,773
  • 7
  • 38
  • 60

1 Answers1

1

You can define a human-readable version of a token name by adding it in quotes after the token name in the %token definition:

%token BECOMES "':='"

This will change the error message to:

unexpected '[', expecting ':='
sepp2k
  • 363,768
  • 54
  • 674
  • 675
  • Thanks! For some strange reason the single quotes *and* the double quotes are printed in the error message (`expecting "':='"`). If I remove the single quotes no quotes are printed (`expecting :=`). I use Bison 3.3.2. – August Karlstrom Apr 03 '21 at 17:30