Re: yacc error handling

Michael C Schweisguth <>
7 Dec 1999 00:34:15 -0500

          From comp.compilers

Related articles
Re: YACC error handling (1989-07-29)
yacc error handling (Ajay Kalhan) (1999-11-19)
Re: yacc error handling (Ajay Kalhan) (1999-11-21)
Re: yacc error handling (Bryan Ewbank) (1999-11-23)
Re: yacc error handling (Zalman Stern) (1999-11-28)
Re: yacc error handling (Michael C Schweisguth) (1999-12-07)
Re: yacc error handling (Bill Fahle) (1999-12-24)
| List of all articles for this month |

From: Michael C Schweisguth <>
Newsgroups: comp.compilers
Date: 7 Dec 1999 00:34:15 -0500
Organization: The University of Arizona
References: 99-11-117 99-11-128 99-11-134 99-11-172
Keywords: yacc, design

I Think That All You Have To Do Is Have A Global List Of All The
Memory You Allocate During The Parse, And Then, You Can Simply
Traverse The Linked List And Delete All The Allocated Memory. This Is
A Fairly Common Technique. If You Make A Tree Node, With Children A
And B, Then You Would Remove A And B From The Linked List And Add The
Tree Node To The List Since Deleting The Tree Node Also Deletes The

The Other Technique Is Deferred Dynamic Memory Allocation. You Only
Allocate At The Tips Of The Production. Hence, You Take Full
Advantadge Of The Yacc Stack. The Only Real Problem With The Yacc
Stack Is A Variable Size String. So, You Could Easily Create A String
Allocator Which Can Free All The Strings At Once. If A Token'S
Structure Is Large, You Could Use The Same Technique. If There Was No
Error, Than Perhaps The String Allocator Would Not Be Freed, But Kept.

Have Fun!

> Bryan Ewbank <> wrote:
> : Since there are parse errors, isn't the program going to exit? If so,
> : why bother cleaning up?

Zalman Stern <> wrote:
> This is precisely the attitude that makes makes compiler generation
> tools (e.g. original lex/yacc) such a pain to use in areas other than
f> traditional batch compiler type applications.

Post a followup to this message

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