From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,e5d23ac8a9173493 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news2.google.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!cyclone1.gnilink.net!gnilink.net!wns14feed!worldnet.att.net!attbi_s22.POSTED!53ab2750!not-for-mail From: "Jeffrey R. Carter" User-Agent: Thunderbird 2.0.0.17 (Windows/20080914) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Using a string as a binary operator References: <8cbb04c3-e789-4b67-897a-fd6f83486bbc@x16g2000prn.googlegroups.com> In-Reply-To: <8cbb04c3-e789-4b67-897a-fd6f83486bbc@x16g2000prn.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: NNTP-Posting-Host: 12.201.97.213 X-Complaints-To: abuse@mchsi.com X-Trace: attbi_s22 1224010283 12.201.97.213 (Tue, 14 Oct 2008 18:51:23 GMT) NNTP-Posting-Date: Tue, 14 Oct 2008 18:51:23 GMT Organization: AT&T ASP.att.net Date: Tue, 14 Oct 2008 18:51:23 GMT Xref: g2news2.google.com comp.lang.ada:8111 Date: 2008-10-14T18:51:23+00:00 List-Id: 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