C-- compiler

germans@cs.vu.nl (Germans DM)
Wed, 5 Oct 1994 13:09:16 GMT

          From comp.compilers

Related articles
C-- compiler germans@cs.vu.nl (1994-10-05)
Re: C-- compiler nickb@harlequin.co.uk (1994-10-11)
| List of all articles for this month |
Newsgroups: comp.compilers
From: germans@cs.vu.nl (Germans DM)
Keywords: C, errors, parse, question
Organization: Fac. Wiskunde & Informatica, VU, Amsterdam
Date: Wed, 5 Oct 1994 13:09:16 GMT

I'm doing a C-- home-made compiler and it's really getting along fine, until
someone told me that I should implement error-recovery.
Now here is my problem:


In my compiler, I can use 2 types of error recovery. Let's say the
compiler has to eat this:


int stupid_function(;)
{
        /* blah, blah */
}


Now this gives the following tokenstream from the lexical analyser:


int
stupid_function
(
;
)
{
}


The compiler goes: I expect a type specifier -> int, OK.
I expect an identifier -> stupid_function, OK.
I expect either a ; or a ( -> (, OK, it's a new function.
I expect a ) -> ERROR!


Here the compiler can do two things, either he can insert a ) and go on or
it can exchange the ; for a ) and go on. The first option would continue
into:


I expect a { -> ERROR! { expected
(insertion of { before the ;)
                                      I expect a statement -> ERROR! illegal statement
(insertion of nothing before the ;)
                                      ENDLESS LOOP!! (until the set max. nrs. of errors)


The second alternative brings:


I expect a { -> ERROR! { expected
(swaps the ) for the {)
                                      I expect a statement -> {, OK, start of new compound stat.
I expect a statement -> }, OK, end of new compound stat.
I expect a } -> ERROR! Unexpected end of file


Both alternatives are unsatisfying. Can anyone help me ?
--
Simm (germans@cs.vu.nl)
--


Post a followup to this message

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