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=-0.4 required=5.0 tests=AC_FROM_MANY_DOTS,BAYES_00 autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a270a1fc28d4f812 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-06-26 21:15:09 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!colt.net!newspeer.clara.net!news.clara.net!psiuk-p2!psiuk-p3!uknet!psiuk-n!news.pace.co.uk!nh.pace.co.uk!not-for-mail From: "Marin David Condic" Newsgroups: comp.lang.ada Subject: Re: OOD in Ada? Date: Wed, 26 Jun 2002 14:47:19 -0400 Organization: Posted on a server owned by Pace Micro Technology plc Message-ID: References: NNTP-Posting-Host: dhcp-200-133.miami.pace.co.uk X-Trace: nh.pace.co.uk 1025117241 8035 136.170.200.133 (26 Jun 2002 18:47:21 GMT) X-Complaints-To: newsmaster@news.cam.pace.co.uk NNTP-Posting-Date: 26 Jun 2002 18:47:21 GMT X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 Xref: archiver1.google.com comp.lang.ada:26738 Date: 2002-06-26T18:47:21+00:00 List-Id: There's more than one way to do just about anything. :-) I'm not sure I understand where you're going with this. I'm not clear if you are in favor of deriving some sort of syntax elements from a base class or not. What do you mean by: "use the Ada type system to encode particular syntax rules"? >From my limited experience with parsing things, I can see how one might say "I've got some sort of tokens or syntax elements that are on the one hand, all the same kind of thing conceptually in that I want to build a tree of them, but on the other hand, they're all different in that they may contain substantially different data..." One way I've done it and seen it done is with discriminated records. They're all the same type so you can build linked data structures with them. Another method is to use tagged records where the base class handles anything common to the tree nodes and you derive new classes to add the variant parts. The new classes are good models of each syntactic element and may need to make reference to each other via a sort of generic pointer. (You want to be able to chase down the parse tree and it will contain heterogeneous data...) The only problem here is that since you're using a single pointer type to point to a variety of different types, you do circumvent some of the type safety you might otherwise get on the pointers. (Its somewhat worse than using a discriminated record since some unrelated classes could be built from the same base type & you risk having pointers that can reference something outside of the controlled subset.) The thing is that when you need to build two classes that might need to reference each other, deriving from a common base type is a good way to do that. Deciding if it is A Good Thing to have mutually referential classes is another matter. MDC -- Marin David Condic Senior Software Engineer Pace Micro Technology Americas www.pacemicro.com Enabling the digital revolution e-Mail: marin.condic@pacemicro.com wrote in message news:UxnS8.606$ci5.107953341@newssvr13.news.prodigy.com... > I can't phrase it well, but this bother me. In parsing, you have a > bunch of terminals and non-terminals and a base non-terminal (something > like "program"). So make a base class of Non_Terminal with children like > "Declarative_Part", "Expression", "Term", etc. That's the general > paradigm for a parser. > Then you have a particular grammar that says that an Expression can have > a Statement as a constituent (in the OP's case), or that a Term can be > followed by an Adding_Operator, and so forth. It seems to me overdoing > things to try to use the Ada type system to encode particular syntax > rules, especially when you consider that a particular grammar may change > due to changes in the language, or to arrange to call semantic routines at > more convenient times, or whatever.