comp.lang.ada
 help / color / mirror / Atom feed
From: george.priv@gmail.com
Subject: Re: Using a string as a binary operator
Date: Tue, 14 Oct 2008 15:01:40 -0700 (PDT)
Date: 2008-10-14T15:01:40-07:00	[thread overview]
Message-ID: <48f50bb6-4ee4-424b-b8bf-4c5d39953632@a19g2000pra.googlegroups.com> (raw)
In-Reply-To: 8cbb04c3-e789-4b67-897a-fd6f83486bbc@x16g2000prn.googlegroups.com

On Oct 14, 11:35 am, Joe <joesmo...@gmail.com> wrote:
> Hey all,
>
> 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;
>
> 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.




  parent reply	other threads:[~2008-10-14 22:01 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
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 [this message]
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