From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,59ea45c31346f2c4 X-Google-Attributes: gid103376,public From: stt@houdini.camb.inmet.com (Tucker Taft) Subject: Re: Ada type (yacc)YYSTYPE is ? Date: 1999/01/18 Message-ID: #1/1 X-Deja-AN: 434052384 Sender: news@inmet.camb.inmet.com (USENET news) X-Nntp-Posting-Host: houdini.camb.inmet.com References: <77qu4d$jt8@lotho.delphi.com> Organization: Intermetrics, Inc. Newsgroups: comp.lang.ada Date: 1999-01-18T00:00:00+00:00 List-Id: tmoran@bix.com wrote: : YACC is designed with a C 'union' type as a typeless, semantic : token information holder variable. What's a good way in Ada to : handle that, hopefully with some help from Ada type checking? : One obvious one is a variant record. Any better ideas? A variant record (with a default for the discriminant) is certainly the most obvious choice. For Ada 95, an access type to a classwide type is another possible solution, using type extension to accommodate the various types to be stored on the parse stack. However, the downside of a access-to-classwide is that you have to worry about storage reclamation, whereas the variant record can be used directly as the component on the array used to implement the parse stack. A simple reclamation scheme for the access-to-classwide solution is to have each type extension maintain its own free list, and a dispatching operation to add an object back onto its free list when no longer needed (you will probably want to add a "next" link into the root type of the class for linking onto the free list). On the other hand, if the parse actions are building up an abstract syntax tree anyway, then you would be allocating the AST nodes on the heap, and these might as well be your parse stack items. -- -Tucker Taft stt@averstar.com http://www.averstar.com/~stt/ Technical Director, Distributed IT Solutions (www.averstar.com/tools) AverStar (formerly Intermetrics, Inc.) Burlington, MA USA