comp.lang.ada
 help / color / mirror / Atom feed
From: "Nick Roberts" <Nick.Roberts@dial.pipex.com>
Subject: Lexical Conundrum
Date: 1998/02/22
Date: 1998-02-22T00:00:00+00:00	[thread overview]
Message-ID: <6cpkda$otl$1@plug.news.pipex.net> (raw)


I have run the following program

   1  with Ada.Text_IO; use Ada.Text_IO;
   2  procedure Test_1 is
   3     subtype UC is Character range'A'..'Z';
   4  begin
   5     Put_Line("Start of Test_1");
   6     if 'a'='a' or'a'in UC then
   7        Put_Line("True branch executed");
   8     end if;
   9     Put_Line("End of Test_1");
  10  end;

through GNAT 3.10, and it compiles and runs fine.  I haven't tried, but I
imagine it would probably work on any Ada compiler, in all likelihood.
But, if you look closely at line 6, you will see the sequence

   or'a'in

in the middle of an expression.
Now, from chapter 2 of the RM, one might get the impression that this could
be parsed as five lexical elements (three identifiers and two apostrophes).
Of course, if a compiler were to parse it that way, the result would be a
syntax error.

For comparison, I have put

   range'A'..'Z';

into line 3.  I don't think there is an ambiguity in parsing this, although
it is very close to the previous example.  Similarly, if the space were to
be removed from just before the example in line 6, the ambiguity would be
resolved there also.

One immediate conclusion, I think, is that the introduction of a one-letter
attribute (in an implementation of the language) could cause difficulties!
Of course, it's hard to imagine a motive for such an attribute, in practice.

Question: would a compiler be in contravention of the RM by rejecting the
above program (with a syntax error in line 6)?  I admit that such a
compiler may be considered to be poorly designed!


== Nick Roberts ================================================
== Croydon, UK                       ===========================
==                                              ================
== Proprietor, ThoughtWing Software                   ==========
== Independent Software Development Consultant            ======
== Nick.Roberts@dial.pipex.com                              ====
== Voicemail & Fax +44 181-405 1124                          ===
==                                                            ==
==           I live not in myself, but I become               ==
===          Portion of that around me; and to me             ==
====         High mountains are a feeling, but the hum        ==
=======      Of human cities torture.
===========                             -- Byron [Childe Harold]







             reply	other threads:[~1998-02-22  0:00 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-02-22  0:00 Nick Roberts [this message]
1998-02-22  0:00 ` Lexical Conundrum Robert Dewar
1998-02-24  0:00   ` John Roberts-Jones
  -- strict thread matches above, loose matches on Subject: below --
1998-02-19  0:00 Nick Roberts
     [not found] ` <EotBMK.MnK@world.std.com>
1998-02-22  0:00   ` Robert Dewar
1998-02-23  0:00     ` Keith Thompson
1998-02-23  0:00       ` Robert Dewar
     [not found]     ` <Eou91J.Es9@world.std.com>
1998-02-23  0:00       ` Robert Dewar
1998-02-26  0:00     ` Dr Steve Sangwine
1998-02-23  0:00   ` Mark A Biggar
1998-02-24  0:00     ` Mats Weber
1998-02-24  0:00       ` Robert Dewar
1998-03-05  0:00         ` Robert I. Eachus
1998-02-23  0:00 ` Jean-Pierre Rosen
1998-02-23  0:00   ` Robert Dewar
replies disabled

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