Improving yacc error messages (zb32)
28 Jul 2004 12:22:35 -0400

          From comp.compilers

Related articles
Improving yacc error messages (2004-07-28)
| List of all articles for this month |

From: (zb32)
Newsgroups: comp.compilers
Date: 28 Jul 2004 12:22:35 -0400
Keywords: yacc, errors, question
Posted-Date: 28 Jul 2004 12:22:35 EDT

Hi, guys.

I need help with improving my syntax error messages.

Right now I just have standard bison error handling where it looks at
possible tokens and

says <token> expected.

Few quetions, if you don't have time to read all, please answer just
on one or two of them.

question 1:

I am not exactly clear on contents of yytable, what does it mean
"portions for different uses" ? What do those portions contain and in
what format?
for example if I have


what do last two expressions mean?

question 2:

if I put an error token in a rule that doesn't have a closing token
like this

stmnts: /* empty string */
                | stmnts '\n'
                | stmnts exp '\n'
                | error

is error token going to match all of the remaining output if syntax
error occurs?

question 2:

what if I have a mid rule where I decide that something's wrong and
want to ignore the whole expression

expr : part1 { some checks here } part2 part3 part4 part5

How can I go about it?

question 3:

If I get an error in lexer, for example closing comment w/o opening
comment, how can I get

the parser to ignore the token or maybe a serie of tokens?
For example if I have a construct IF outside of a function in C++ I
need to ignore the whole thing and continue parsing next function.
Is it just a matter of smart error token usage?

question 4:

In Bison code there is YYFAIL macro that goes to yyerrlab:
Is it the default action when an error is encountered?

question 5:

For example if I have a piece of program like this:


when parser reads "b" it errors, I print "missing semicolon" but then
I want to continue parsing. How do I put back "b" so that b=2; is
parsed successfully.

thanks in advance

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.