From: "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: Building an encapsulated library that uses GNAT sockets under Windows
Date: Thu, 28 Apr 2016 14:47:43 -0700
Date: 2016-04-28T14:47:43-07:00 [thread overview]
Message-ID: <nfu07h$r5b$1@dont-email.me> (raw)
In-Reply-To: <nftrfe$n4p$1@loke.gir.dk>
On 04/28/2016 01:23 PM, Randy Brukardt wrote:
>
> A typical case would be a lexer for numeric literals, where one wants to
> discard the underscores and keep the other characters. That would look
> something like:
>
> while not End_of_File loop
> case Next_Char is
> when '0'..'9' =>
> null;
> when '+' | '-' =>
> {some code}
> when 'E' | 'e' =>
> {some code}
> when '_' =>
> if Last_Char = '_' then
> Error (...);
> else
> goto Continue; -- Skip further processing.
> end if;
> when others =>
> exit; -- We've reached the end of the number.
> end case;
> {Store the Next_Char into the literal token}
> <<Continue>>
> end loop;
>
> To avoid the goto/continue, you'd have to introduce a Boolean, or duplicate
> the "Store" code, or make the "Store" code into a subprogram, and make
> duplicate calls on that. None of which is clearer, or faster, than the above
> code. (Faster matters here as this loop is the third most used of the inner
> lexer loops, behind comments and identifiers. And a lexer is one of the top
> CPU users in a typical compiler.)
Or do
when '_' =>
if Last_Char = '_' then
Error (...);
end if;
when others =>
exit; -- We've reached the end of the number.
end case;
if Next_Char /= '_' then
{Store Next_Char into the literal token}
end if;
end loop;
which is still clearer than the goto.
Maybe you have some more complex, more deeply nested, real-world example where
this kind of alternative isn't possible. I've never encountered one.
--
Jeff Carter
"[T]he Musgroves had had the ill fortune
of a very troublesome, hopeless son, and
the good fortune to lose him before he
reached his twentieth year ..."
Persuasion
154
next prev parent reply other threads:[~2016-04-28 21:47 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-21 12:59 Building an encapsulated library that uses GNAT sockets under Windows Dmitry A. Kazakov
2016-04-22 7:58 ` ahlan.marriott
2016-04-22 8:23 ` Dmitry A. Kazakov
2016-04-23 9:20 ` Ahlan
2016-04-23 9:48 ` Dmitry A. Kazakov
2016-04-23 14:45 ` ahlan.marriott
2016-04-23 19:56 ` Dmitry A. Kazakov
2016-04-23 21:16 ` Simon Wright
2016-04-24 8:13 ` ahlan
2016-04-24 8:31 ` Simon Wright
2016-04-26 19:43 ` ahlan.marriott
2016-04-26 20:24 ` Simon Wright
2016-04-26 22:32 ` Jeffrey R. Carter
2016-04-27 22:16 ` Randy Brukardt
2016-04-27 23:43 ` Jeffrey R. Carter
2016-04-28 5:18 ` J-P. Rosen
2016-04-28 5:59 ` Jeffrey R. Carter
2016-05-09 22:32 ` David Thompson
2016-04-28 20:23 ` Randy Brukardt
2016-04-28 21:47 ` Jeffrey R. Carter [this message]
2016-04-28 5:13 ` J-P. Rosen
2016-04-26 20:20 ` Dmitry A. Kazakov
2016-04-26 21:23 ` Simon Wright
2016-04-27 6:53 ` Simon Wright
2016-04-27 7:25 ` ahlan
2016-04-27 8:27 ` Dmitry A. Kazakov
2016-04-27 9:59 ` Simon Wright
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox