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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,e5d23ac8a9173493 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!a19g2000pra.googlegroups.com!not-for-mail From: george.priv@gmail.com Newsgroups: comp.lang.ada Subject: Re: Using a string as a binary operator Date: Tue, 14 Oct 2008 15:01:40 -0700 (PDT) Organization: http://groups.google.com Message-ID: <48f50bb6-4ee4-424b-b8bf-4c5d39953632@a19g2000pra.googlegroups.com> References: <8cbb04c3-e789-4b67-897a-fd6f83486bbc@x16g2000prn.googlegroups.com> NNTP-Posting-Host: 151.196.71.114 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1224021700 6530 127.0.0.1 (14 Oct 2008 22:01:40 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 14 Oct 2008 22:01:40 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: a19g2000pra.googlegroups.com; posting-host=151.196.71.114; posting-account=VnNb3AoAAACTpRtCcTrcjmPX7cs92k1Q User-Agent: G2/1.0 X-HTTP-Via: 1.1 SPARKS X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:8112 Date: 2008-10-14T15:01:40-07:00 List-Id: On Oct 14, 11:35=A0am, Joe wrote: > Hey all, > > I'm trying to build a simple stack the evaluates expressions in > postfix notation (i.e. "1 2 +"). =A0I can't find a way to use the > operator directly when I get to it. =A0When I get to the =A0"+", but how > do I apply this string to 1 and 2? =A0The best I can do is make a case > statement that has a case for each binary operator, but this seems > very klunky. =A0I know you can write "+"(1,2) to return 3 but how do I > get Ada to recognize the string as an operator? =A0Here's a short > example of what I would like to do: > > with Ada.Integer_Text_IO; =A0use Ada.Integer_Text_IO; > procedure Operators is > =A0 =A0Plus : String :=3D "+"; > begin > =A0 =A0Put( Plus(1,2)); > end Operators; > > Thanks, > Joe You are confusing compile time and run time phases of your program's life. When you call "+"(a,b), it is treated as any other function (Could have been Add(a,b)). Ada overload feature allows for more convenient substitution in form a+b. The construct is recognized during compilation of the source code. At run time compiler is no longer used and sometimes unavailable. So you have to write your own parser that will handle your input string. There is plentiful code samples out there on the WEB in variety of languages I am sure. George.