comp.lang.ada
 help / color / mirror / Atom feed
* parse word from a string
@ 2002-11-12 19:25 Sarah Thomas
  2002-11-12 21:36 ` Michal Nowak
  2002-11-13  9:46 ` Pascal Obry
  0 siblings, 2 replies; 6+ messages in thread
From: Sarah Thomas @ 2002-11-12 19:25 UTC (permalink / raw)


I'm new to Ada, can someone help me with this.
I need to read a text file word by word. THe approach I took is to
read each line of the text file and then parse the words out. I have
read each line, now I have a hard time to parse the line into words
and store them in an array. can someone help me with this.
thanks



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: parse word from a string
  2002-11-12 19:25 parse word from a string Sarah Thomas
@ 2002-11-12 21:36 ` Michal Nowak
  2002-11-13  9:46 ` Pascal Obry
  1 sibling, 0 replies; 6+ messages in thread
From: Michal Nowak @ 2002-11-12 21:36 UTC (permalink / raw)


On 2002-11-12 at 11:25 mabes180@aol.com wrote:

>I'm new to Ada, can someone help me with this.
>I need to read a text file word by word. THe approach I took is to
>read each line of the text file and then parse the words out. I have
>read each line, now I have a hard time to parse the line into words
>and store them in an array. can someone help me with this.
>thanks

The procedure Find_Token from package Ada.Strings.xxxxx (xxxxx is
Fixed, Bouded or Unbounded, depending which Strings you use) is
what you are looking for. See Ada Reference Manual, section 
A.4.3, A.4.4, A.4.5 in particular. 

Hope this helps,
Michal


-- -----------------------------------------------------------------
--   ___        _
--  / _ \      | |                      I Choose Ada:
-- | |_| |  ___| |   _____   The Most Trusted Name in Software (TM)
-- |  _  | | __  |  | __  | 
-- |_| |_| |_____|_ |_____|_ http://www.adaic.org/whyada/choose.html
--
-- -----------------------------------------------------------------




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: parse word from a string
  2002-11-12 19:25 parse word from a string Sarah Thomas
  2002-11-12 21:36 ` Michal Nowak
@ 2002-11-13  9:46 ` Pascal Obry
  2002-11-13 17:23   ` Mário Amado Alves
  1 sibling, 1 reply; 6+ messages in thread
From: Pascal Obry @ 2002-11-13  9:46 UTC (permalink / raw)



mabes180@aol.com (Sarah Thomas) writes:

> I'm new to Ada, can someone help me with this.
> I need to read a text file word by word. THe approach I took is to
> read each line of the text file and then parse the words out. I have
> read each line, now I have a hard time to parse the line into words
> and store them in an array. can someone help me with this.
> thanks

If you are using GNAT be sure to look at GNAT.AWK.

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|         http://perso.wanadoo.fr/pascal.obry
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: parse word from a string
  2002-11-13  9:46 ` Pascal Obry
@ 2002-11-13 17:23   ` Mário Amado Alves
  2002-11-14 17:41     ` Pascal Obry
  0 siblings, 1 reply; 6+ messages in thread
From: Mário Amado Alves @ 2002-11-13 17:23 UTC (permalink / raw)


> If you are using GNAT be sure to look at GNAT.AWK. (Pascal)

Uhg, no! Look at GNAT.Spitbol ;-)

--MAA



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: parse word from a string
  2002-11-13 17:23   ` Mário Amado Alves
@ 2002-11-14 17:41     ` Pascal Obry
  2002-11-15 11:12       ` Mário Amado Alves
  0 siblings, 1 reply; 6+ messages in thread
From: Pascal Obry @ 2002-11-14 17:41 UTC (permalink / raw)



maa@liacc.up.pt (M�rio Amado Alves) writes:

> > If you are using GNAT be sure to look at GNAT.AWK. (Pascal)
> 
> Uhg, no! Look at GNAT.Spitbol ;-)

I disagree :) GNAT.AWK handles files directly. In GNAT.Spitbol you still have
to open and read each lines. And since the problem at hand seems to just slice
a string with a set of separators, GNAT.AWK seems just fine ;)

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|         http://perso.wanadoo.fr/pascal.obry
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: parse word from a string
  2002-11-14 17:41     ` Pascal Obry
@ 2002-11-15 11:12       ` Mário Amado Alves
  0 siblings, 0 replies; 6+ messages in thread
From: Mário Amado Alves @ 2002-11-15 11:12 UTC (permalink / raw)


"If you are using GNAT be sure to look at GNAT.AWK. (Pascal)"

"Uhg, no! Look at GNAT.Spitbol ;-)" (MAA)
 
"I disagree :) GNAT.AWK handles files directly. In GNAT.Spitbol you
still have to open and read each lines. And since the problem at hand
seems to justslice a string with a set of separators, GNAT.AWK seems
just fine ;)" (Pascal)

Actually the original problem is "read words from a file", and for
that a simple character automaton in 'pure' Ada suffices, e.g.

  C : Character
  Word : Unbounded_String;
begin
  loop
    Get_Immediate (C);
    if Is_Graphic (C) and C /= ' ' then
      Append (Word, C);
    else
      Process (Word);
      Word := Null_Unbounded_String;
    end if;
  end loop;
exception
  when End_Error =>
    if Word /= Null_Unbounded_String then Process (Word); end if;

I was just advocating Spitbol over AWK in the case of general pattern
matching. You seem to agree that Spitbol might be better for complex
problems. And Spitbol is also good enough for simple problems. Ergo,
Spitbol is better ;-)

More seriously, it is better strictly in a Reduced Technology Mix
framework.

Again, for the simple problem at hand, I follow Robert Dewar's famous
adage: "don't use pattern matching".

Cheers,
--MAA



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2002-11-15 11:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-12 19:25 parse word from a string Sarah Thomas
2002-11-12 21:36 ` Michal Nowak
2002-11-13  9:46 ` Pascal Obry
2002-11-13 17:23   ` Mário Amado Alves
2002-11-14 17:41     ` Pascal Obry
2002-11-15 11:12       ` Mário Amado Alves

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