comp.lang.ada
 help / color / mirror / Atom feed
From: "Marin David Condic" <dont.bother.mcondic.auntie.spam@[acm.org>
Subject: Re: OOD in Ada?
Date: Wed, 26 Jun 2002 14:47:19 -0400
Date: 2002-06-26T18:47:21+00:00	[thread overview]
Message-ID: <afd27p$7r3$1@nh.pace.co.uk> (raw)
In-Reply-To: UxnS8.606$ci5.107953341@newssvr13.news.prodigy.com

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


<tmoran@acm.org> 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.





  reply	other threads:[~2002-06-26 18:47 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-06-21 16:39 OOD in Ada? David Crocker
2002-06-21 17:20 ` Pat Rogers
2002-06-21 19:37   ` Ed Falis
2002-06-23  3:05   ` Ted Dennison
2002-06-23  7:03     ` tmoran
2002-06-24 21:41       ` Ted Dennison
2002-06-24 14:19     ` Stephen Leake
2002-06-21 17:22 ` Marin David Condic
2002-06-22  4:42 ` Jeffrey Carter
2002-06-22  9:18 ` Dr. Michael Paus
2002-06-22  9:47   ` Pascal Obry
2002-06-22 13:11     ` Dr. Michael Paus
2002-06-22 13:46       ` OOD in Ada? Correction Dr. Michael Paus
2002-06-22 18:21         ` Simon Wright
2002-06-28 23:57         ` Randy Brukardt
2002-07-09  8:45           ` Preben Randhol
2002-07-09 17:12             ` Mark Biggar
2002-07-09 19:40             ` Randy Brukardt
2002-06-23  3:33   ` OOD in Ada? steve_H
2002-06-23  4:55     ` Jim Rogers
2002-06-23  5:33       ` achrist
2002-06-25 18:00       ` Georg Bauhaus
2002-06-25 18:55         ` Marin David Condic
2002-07-07 18:19           ` Daniel Dudley
2002-06-23  7:46     ` Dr. Michael Paus
2002-06-24  5:06       ` steve_H
2002-06-23 19:26   ` Chad R. Meiners
2002-06-22 22:47 ` Dmitry A.Kazakov
2002-06-24 20:03 ` Kevin Cline
2002-06-25 13:32   ` David Crocker
2002-06-25 13:58     ` Marin David Condic
2002-06-26 18:16       ` tmoran
2002-06-26 18:47         ` Marin David Condic [this message]
2002-06-27 18:23           ` tmoran
2002-06-28 13:09             ` Marin David Condic
2002-06-26  0:59     ` Hyman Rosen
2002-06-26  4:57       ` Jim Rogers
2002-06-26 12:49       ` Marin David Condic
2002-06-26  9:01     ` Fraser Wilson
2002-06-29  0:08       ` Randy Brukardt
2002-07-01 11:50         ` Fraser Wilson
2002-07-05 20:02     ` Stephen J. Bevan
2002-07-09 19:19 ` Craig Carey
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox