Error recovery in bison...

mmoretti@max.tiac.net (Mike Moretti)
Mon, 23 Jan 1995 01:23:05 GMT

          From comp.compilers

Related articles
Error recovery in bison... mmoretti@max.tiac.net (1995-01-23)
| List of all articles for this month |
Newsgroups: comp.compilers
From: mmoretti@max.tiac.net (Mike Moretti)
Keywords: yacc, errors, question, comment
Organization: Object House, Inc.
Date: Mon, 23 Jan 1995 01:23:05 GMT

Hi,


I'm trying to use bison/flex to write a preprocessor/translator.
I've run into a stumbling block though.


Here's what I need to do:


  ArgSelection : ARG INPUTID InputIdList
                            | ARG OUTPUTID OutputIdList
                            ;


However, I can't make up my mind whether or not the lexical scanner should
return INPUTID (if the ID in the symbol table is an INPUTID) or just plain
ID (so I can check myself in the action to see whether or not it's an
INPUTID). The problem is that if I code it the way above, I can't give
meaningful errors in case someone uses an already defined or undefined
ID. If I do it the above way, all errors will just pass to yyerror
and I won't know what happened. But if I try to figure out the type
of ID in the action instead, I can't see any way to make the grammar follow
InputIdList or OutputIdList based on what I've figured out (I've tried
YYBACKUP for this but it doesn't seem to work).


The other way I tried was to add the following line:


                            | ARG error


But, then I can't tell what caused the error, whether it was an ID
or something else, and I can't see what the next token is...


How can I make my program give meaningful error messages. Is there
a better way to do error recovery in this type of case (or in general)?


Thanx in advance!


Mike Moretti mmoretti@tiac.net
Software Engineer
Object House, Inc.
[I'd use a lexical hack, have my code tell the lexer to stuff a fake symbol to
direct the parse, e.g.
  ArgSelection : ARG idhack INTOK InputIdList
                            | ARG idhack OUTTOK OutputIdList
                            ;
  idhack : ID { code that tells the lexer to return INTOK or OUTTOK next }
Ugly but effective. -John]
--


Post a followup to this message

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