From: "Jeffrey R. Carter" <spam.jrcarter.not@spam.acm.org>
Subject: Re: Using a string as a binary operator
Date: Tue, 14 Oct 2008 18:51:23 GMT
Date: 2008-10-14T18:51:23+00:00 [thread overview]
Message-ID: <LS5Jk.332480$TT4.121820@attbi_s22> (raw)
In-Reply-To: <8cbb04c3-e789-4b67-897a-fd6f83486bbc@x16g2000prn.googlegroups.com>
Joe wrote:
>
> I'm trying to build a simple stack the evaluates expressions in
> postfix notation (i.e. "1 2 +"). I can't find a way to use the
> operator directly when I get to it. When I get to the "+", but how
> do I apply this string to 1 and 2? The best I can do is make a case
> statement that has a case for each binary operator, but this seems
> very klunky. I know you can write "+"(1,2) to return 3 but how do I
> get Ada to recognize the string as an operator? Here's a short
> example of what I would like to do:
The short answer is that you can't. You have to evaluate "1" and "2" to get
values of some numeric type and push them on a stack, then find a branch in an
if-elsif-else chain that matches your operator string, and in that branch pop
the operands and apply the appropriate operator to them. See
PragmARC.Postfix_Calculator for an (Ada-95) example.
http://pragmada.home.mchsi.com/
--
Jeff Carter
"Every sperm is sacred."
Monty Python's the Meaning of Life
55
next prev parent reply other threads:[~2008-10-14 18:51 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-14 15:35 Using a string as a binary operator Joe
2008-10-14 17:05 ` Dmitry A. Kazakov
2008-10-14 18:51 ` Jeffrey R. Carter [this message]
2008-10-15 15:22 ` Adam Beneschan
2008-10-15 17:23 ` Jeffrey R. Carter
2008-10-15 19:32 ` sjw
2008-10-16 8:14 ` Dmitry A. Kazakov
2008-10-14 22:01 ` george.priv
2008-10-15 3:51 ` Gene
2008-10-15 5:45 ` anon
2008-10-15 12:18 ` Joe
2008-10-15 13:43 ` John McCormick
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox