comp.lang.ada
 help / color / mirror / Atom feed
* help on Ada project
@ 1999-12-01  0:00 phantom119
  1999-12-01  0:00 ` Ted Dennison
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: phantom119 @ 1999-12-01  0:00 UTC (permalink / raw)


I need some help on Ada, we are to create a
lexical analyzer and we are stuck on the fact that
it's giving us some problems on string comparison,
we are using a case statement to compare strings,
since just a few words the analyzer should
recognize for example "begin" and print out on the
screen TBegin, we are using a case statement but
for some reason I guess we are not using the right
syntax, any suggestions on how would you do that?


Sent via Deja.com http://www.deja.com/
Before you buy.




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

* Re: help on Ada project
  1999-12-01  0:00 help on Ada project phantom119
@ 1999-12-01  0:00 ` Ted Dennison
  1999-12-01  0:00 ` Geoff Bull
  1999-12-01  0:00 ` Peter Milliken
  2 siblings, 0 replies; 5+ messages in thread
From: Ted Dennison @ 1999-12-01  0:00 UTC (permalink / raw)


In article <82204n$f3n$1@nnrp1.deja.com>,
  phantom119@my-deja.com wrote:

> it's giving us some problems on string comparison,
> we are using a case statement to compare strings,

I suspect you are having trouble becuase you are trying to use a string
in a case statement. Case statements can only be used on discrete types,
not compound types like strings, arrays, or records. To get the same
effect on a string, you would need to use an "if...elsif...elsif.."
construct.

Another possibility would be to use nested case statements on individual
characters in the string. That would probably make for a faster lexer,
but its a lot more work.

--
T.E.D.


Sent via Deja.com http://www.deja.com/
Before you buy.




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

* Re: help on Ada project
  1999-12-01  0:00 help on Ada project phantom119
  1999-12-01  0:00 ` Ted Dennison
  1999-12-01  0:00 ` Geoff Bull
@ 1999-12-01  0:00 ` Peter Milliken
  1999-12-02  0:00   ` John McCabe
  2 siblings, 1 reply; 5+ messages in thread
From: Peter Milliken @ 1999-12-01  0:00 UTC (permalink / raw)


Nope, perhaps if you posted your code then we can help you by pointing
out what is wrong. No freebies here, I'm sorry to say :-)

Peter

phantom119@my-deja.com wrote:

> I need some help on Ada, we are to create a
> lexical analyzer and we are stuck on the fact that
> it's giving us some problems on string comparison,
> we are using a case statement to compare strings,
> since just a few words the analyzer should
> recognize for example "begin" and print out on the
> screen TBegin, we are using a case statement but
> for some reason I guess we are not using the right
> syntax, any suggestions on how would you do that?
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.





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

* Re: help on Ada project
  1999-12-01  0:00 help on Ada project phantom119
  1999-12-01  0:00 ` Ted Dennison
@ 1999-12-01  0:00 ` Geoff Bull
  1999-12-01  0:00 ` Peter Milliken
  2 siblings, 0 replies; 5+ messages in thread
From: Geoff Bull @ 1999-12-01  0:00 UTC (permalink / raw)
  To: phantom119

phantom119@my-deja.com wrote:
> 
> I need some help on Ada, we are to create a
> lexical analyzer and we are stuck on the fact that
> it's giving us some problems on string comparison,
> we are using a case statement to compare strings,
> since just a few words the analyzer should
> recognize for example "begin" and print out on the
> screen TBegin, we are using a case statement but
> for some reason I guess we are not using the right
> syntax, any suggestions on how would you do that?

I assume this is a homework assignment?

For case statement syntax see the Ada Reference Manual:
http://www.adahome.com/rm95/rm9x-05-04.html
In short, you can't use a case statement to compare strings,
because they are not a discrete type.
Since you only have a few strings you could just use
if statements. For a more extensible approach, you could
search a table.

You might want to study the gnat source which contains a
good example of a lexical analyzer.
ftp://cs.nyu.edu/pub/gnat/gnat-3.12p-src.tar.gz
start in the file scn.adb




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

* Re: help on Ada project
  1999-12-01  0:00 ` Peter Milliken
@ 1999-12-02  0:00   ` John McCabe
  0 siblings, 0 replies; 5+ messages in thread
From: John McCabe @ 1999-12-02  0:00 UTC (permalink / raw)


Peter Milliken <peter.milliken@australia.boeing.com> wrote:

>Nope, perhaps if you posted your code then we can help you by pointing
>out what is wrong. No freebies here, I'm sorry to say :-)

A hint - case selectors must be discrete types in Ada. Strings are not
discrete types.

>
>Peter
>
>phantom119@my-deja.com wrote:
>
>> I need some help on Ada, we are to create a
>> lexical analyzer and we are stuck on the fact that
>> it's giving us some problems on string comparison,
>> we are using a case statement to compare strings,
>> since just a few words the analyzer should
>> recognize for example "begin" and print out on the
>> screen TBegin, we are using a case statement but
>> for some reason I guess we are not using the right
>> syntax, any suggestions on how would you do that?
>>
>> Sent via Deja.com http://www.deja.com/
>> Before you buy.
>


Best Regards
John McCabe <john@assen.demon.co.uk>




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

end of thread, other threads:[~1999-12-02  0:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-12-01  0:00 help on Ada project phantom119
1999-12-01  0:00 ` Ted Dennison
1999-12-01  0:00 ` Geoff Bull
1999-12-01  0:00 ` Peter Milliken
1999-12-02  0:00   ` John McCabe

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