From: Nick Roberts <nick.roberts@acm.org>
Subject: Re: Question about Ada.Unchecked_Conversion
Date: Sat, 30 Oct 2004 17:30:07 +0100
Date: 2004-10-30T17:30:07+01:00 [thread overview]
Message-ID: <2uhtslF2bkb2mU1@uni-berlin.de> (raw)
In-Reply-To: <35f054ea.0410300223.773b722b@posting.google.com>
skidmarks wrote:
> I don't have the full picture of what you're trying to do so my answer
> may be off the mark.
I think you're dead right in principle, and slightly off only in a few
minor details.
> When I build a custom lexor I include a (usually) 256 cell array. The
> cell is mapped one-to-one with (any) 256 representation of the
> character set in use, and 256 has the property of guaranteeing nor
> constraint errors. The contents of each cell is a enumeration
> representing the purpose of the mapped character. My lexer is built
> around this.
Exactly how I do it. Which is not to say that it is necessarily the best
possible way, but I have used it with success in the past.
> For example:
>
> type enum { ign, sep, op, sym, num, hex, ... );
type Character_Category is
( Ignore, Separator, Operator, Symbolic, [and so on] );
> type enum_Map is array ( Integer range 1 .. 256 ) of enum;
>
> Map : constant enum_Map := ( ign, ... sep, ... );
Cat_Of: constant array (Character) of Character_Category :=
( ',' | ';' | ':' | '(' | ')' => Separator,
'+' | '-' | '*' | '/' => Operator,
[and so on],
others => Ignore );
> begin --
>
> if ( enum_Map( Character'Pos(char) ) = <> ) then <> end if;
if Cat_Of(Char) = Separator then
...
> or
>
> case enum_Map( Character'Pos(char) ) is
> when ign => <>
> when sep => <>
> when op => <>
> when sym => <>
> when num => <>
case Cat_Of(Char) is
when Ignore =>
null;
when Separator =>
if Char = ')' then
End_of_List := True;
elsif Char /= ',' then
raise Syntax_Error;
end if;
if Id = "" then
raise Syntax_Error;
end if;
Append( Id_List, Id );
Clear( Id );
Get_Next_Character;
[and so on]
> and so on.
>
> I use a Moore Machine for my finite state machine, the arcs
> representing the transition states (ign, sep, ...) and actions
> associated with taking the transition.
--
Nick Roberts
next prev parent reply other threads:[~2004-10-30 16:30 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-10-29 12:46 Question about Ada.Unchecked_Conversion Eric Jacoboni
2004-10-29 14:22 ` Dmitry A. Kazakov
2004-10-29 14:26 ` Jean-Pierre Rosen
2004-10-29 15:15 ` Nick Roberts
2004-10-29 15:47 ` Eric Jacoboni
2004-10-30 10:23 ` skidmarks
2004-10-30 16:30 ` Nick Roberts [this message]
2004-10-30 17:18 ` Eric Jacoboni
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox