comp.lang.ada
 help / color / mirror / Atom feed
From: tmoran@acm.org
Subject: Re: OOD in Ada?
Date: Thu, 27 Jun 2002 18:23:07 GMT
Date: 2002-06-27T18:23:07+00:00	[thread overview]
Message-ID: <fKIS8.801$X14.133162217@newssvr13.news.prodigy.com> (raw)
In-Reply-To: afd27p$7r3$1@nh.pace.co.uk

> 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"?
   I presume the OP wants to have things along the line of

     type Adding_Operator is tagged record ...
       Op_Char : character;
     end record;
     type Simple_Expression is tagged record
       Left : Access_Simple_Expression;
       Add_Op : Access Adding_Operator;
       Right  : Access_Term;
     end record;

etc. and the problem is this can't be broken into one class = one package
because of mutual references.
  The alternative under discussion has

     type Non_Terminal is abstract tagged null record;
     type Access_Non_Terminal is access all Non_Terminal'class;

     type Simple_Expression is new Non_Terminal with record
       Components : List_Of_Non_Terminals;
     end record;

and so forth, and there's no problem with separate packages because
everything refers back to the base class Non_Terminal.  In the OP's
scenario, the compiler will catch, as a type mismatch, an attempt to set
The_Simple_Expression.Right := Access_Adding_Operator;
In the alternative, the compiler won't know that
The_Simple_Expression.Components(3) := Adding_Operator'access
is a mistake and thus the compiler can't warn you.

  It seems to me that the type system of a program should be rather basic
and one should at least hope there are no, or minimal, changes during
development.  The particular BNF for a language, in my experience, may
however be modified quite late in the game.  You may actually want to
modify the language you are parsing, or, more commonly, you want to
relabel and shuffle around some things so that certain productions are
recognized, and call semantic routines, at slightly different points.
For instance, you might want to change

  simple_expression : term       {process_term($1);}
    | simple_expression adding_operator term  {add_expr($1,$2,$3);}
to
  simple_expression : term       {calculate_term($1);}
      | first_part term          {apply_op_to($2);}
  first_part :  simple_expression adding_operator {push_then_note_op($2);}

  The more closely the BNF is mapped to the types, the more any simple
change to the BNF will require changes to the types.  Worse, if the types
are one-one mapped to packages, even the package structure of the program
must change.  The likelihood of such changes late in development seems to
me a very bad idea.

  In the Access_Non_Terminal version you do indeed lose compiler type
checking.  But in this sort of app, the parser is supposed to be
guaranteeing that only legitimate things get stored, eg, the parser
should disallow "2 + -" and thus the semantic routine add_expr will
never be called with its third parameter an adding operator.
So giving up type checking is not much of a loss.



  reply	other threads:[~2002-06-27 18:23 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
2002-06-27 18:23           ` tmoran [this message]
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