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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC 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-7-bit Path: g2news1.google.com!news2.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!newsfeed.r-kom.de!news-nue1.dfn.de!news-koe1.dfn.de!usenet-feed.fhg.de!npeer.de.kpn-eurorings.net!npeer-ng1.kpn.DE!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Using a string as a binary operator Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <8cbb04c3-e789-4b67-897a-fd6f83486bbc@x16g2000prn.googlegroups.com> Date: Tue, 14 Oct 2008 19:05:40 +0200 Message-ID: <1p57jbf1um2x8.1mk21y75746rt$.dlg@40tude.net> NNTP-Posting-Date: 14 Oct 2008 19:05:43 CEST NNTP-Posting-Host: d25742f6.newsspool1.arcor-online.net X-Trace: DXC=7b2:U7P;REoPKPPVf;4hUjic==]BZ:afn4Fo<]lROoRaFl8W>\BH3Ybi On Tue, 14 Oct 2008 08:35:23 -0700 (PDT), 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: > > with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; > procedure Operators is > Plus : String := "+"; > begin > Put( Plus(1,2)); > end Operators; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; procedure Operators is function Plus (L, R : Integer) return Integer renames "+"; begin Put (Plus (1, 2)); end Operators; P.S. I am quite sure that this is not what you need. You don't need strings in order to evaluate an expression. Evaluation of an expression /= parsing an expression. It is unclear which one you actually want, or maybe both. P.P.S. Ada does not "recognize strings as operators." "+" when used to declare or reference + is technically not a string. It is a string literal. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de