comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Data_Error and Enumeration_IO
Date: Fri, 13 Jan 2012 18:09:48 -0600
Date: 2012-01-13T18:09:48-06:00	[thread overview]
Message-ID: <jeqh4g$peo$1@munin.nbi.dk> (raw)
In-Reply-To: jeq9ib$1ouu$1@adenine.netfront.net

"Jeffrey Carter" <spam.jrcarter.not@spam.not.acm.org> wrote in message 
news:jeq9ib$1ouu$1@adenine.netfront.net...
> On 01/13/2012 02:30 PM, John McCormick wrote:
>>
>> Never be surprised about another's ignorance.  I wasn't in the Ada
>> world during the discussions in the 1980s.  The only thing in Jeff's
>> and Georg's notes of which I had not known was the reference to the
>> material on Data_Error and real types.  From that it seems that the
>> parsing of a potential floating point number uses knowledge of
>> previously entered characters.  For example, if you enter "1.2E." it
>> recognizes that the second decimal point is an error.  Yet when you
>> enter "abc" in my original example for enumeration IO, it cannot
>> recognize that no valid enumeration literal starts with an a.  It has
>> to process the entire identifier before it can see that. So the crux
>> of my question is why doesn't the consumption of characters for
>> enumeration input behave like that of real input. It doesn't really
>> matter other than to satisfy my curiosity.
>
> The consumption of characters is the same in both case: they consume 
> characters as long as the characters follow the syntax of a literal for 
> the type class (the class of floating-point types in one case, of 
> enumeration types in the other). For floating-point types, that's anything 
> that's a valid real literal, even if it's outside the range of the type. 
> For an enumeration it's anything that's a valid identifier or character 
> literal. Equivalent examples to "1.2E." for an enumeration type are "'ab" 
> or "a_*". Note that enumeration input will consume all of "'a'" even if 
> the enumeration type has no character literals.

Right. The important point here is that the consumption of characters is not 
related in any way to the actual subtype being read; it only depends on the 
syntax of the appropriate literals.

When you ask why "abc" is read even if there is no literal that begins with 
'a', imagine a similar case for a real number:

     subtype Nines is Float range 9.0 .. 9.9;

If a Get for Nines is given "1.2", this will be completely read even though 
no legal value of subtype Nines could start with '1'.

As to why it is done this way, it's hard to imagine how else it could be 
done. To reject the "abc" example at the 'a', for instance, we would have to 
do a brute force search in a table of potentially hundreds of enumeration 
literals to see if any start with 'a', then repeat that to see if any start 
with "ab", and so on. If the literals are long and the number of literals is 
high, this is going to be a N**2 algorithm -- and I don't think I want my 
input to do that (there is a built-in denial of service possibility).

                                                     Randy.





  reply	other threads:[~2012-01-14  0:09 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-12 22:41 Data_Error and Enumeration_IO John McCormick
2012-01-12 23:02 ` Jeffrey Carter
2012-01-12 23:28 ` Georg Bauhaus
2012-01-13  0:10 ` Randy Brukardt
2012-01-13  8:33   ` Dmitry A. Kazakov
2012-01-13 21:30   ` John McCormick
2012-01-13 22:00     ` Jeffrey Carter
2012-01-14  0:09       ` Randy Brukardt [this message]
2012-01-14  9:51         ` Dmitry A. Kazakov
2012-01-14 12:25         ` Niklas Holsti
replies disabled

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