August Karlstrom
August Karlstrom

Reputation: 11377

Printing multi-character tokens in YACC error messages

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 :=.

Upvotes: 0

Views: 98

Answers (1)

sepp2k
sepp2k

Reputation: 370435

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 ':='

Upvotes: 1

Related Questions