Related articles |
---|
yacc error clauses jk@cs.man.ac.uk (1993-07-15) |
Re: yacc error clauses babu@wipro.wipsys.soft.net (1993-07-20) |
Newsgroups: | comp.compilers |
From: | jk@cs.man.ac.uk (John Kewley) |
Keywords: | yacc, errors, question, comment |
Organization: | ICL Computers Limited, EDS Project |
Date: | Thu, 15 Jul 1993 14:23:31 GMT |
I have the following aims with my compiler (C++ + yacc):
1. Don't stop at first syntax error, keep going and try and find more
(ie recover).
2. When errors are detected, or I am recovering, release all dynamically
allocated store to reduce memory leaks (compiler can be run standalone
or as part of larger system which makes repeated calls to the compiler).
Are there any suggestions for conventions on how to sort this out,
avoiding any extra conflicts. yyerrok seems OK for me, but my placement of
the error rules seems a bit haphazard.
Comments on the following please?
item_list
: item
{ $$= $1; }
| item_list COMMA item
{ $3->add_item($1);
$$= $3; }
| item_list COMMA error
{ delete $1;
$$= 0; }
What other error productions would you expect in the above?
How would it be used:
item_list_use
: item_list EQ item_list
{ $$= new item_list_use($1, $3); }
What error productions do we need for item_list_use?
One of my problems is that I allocate store to contain identifiers when
they are lexed. If they are not parsed due to an earlier error, the store
is never reclaimed.
Any help would be gratefully received, thanks,
--
John M Kewley
ICL Computers Limited, Wenlock Way, West Gorton, Manchester. M12 5DR
Tel: (+44) 61 223 1301 X2138 Email: jk@fiveg.icl.co.uk or jk@cs.man.ac.uk
[Looks like a reasonable place for an error rule to me, since after a comma
is the only obvious place to resynchronize. For storage management, I
usually make a little private allocator that chains together chunks gotten
from malloc, so I can then release an entire chain when I need to. -John]
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.