comp.lang.ada
 help / color / mirror / Atom feed
From: Poul-Erik Andreasen <poulerik@pea.dk>
Subject: Re: Dynamic functions
Date: Thu, 09 Aug 2007 20:17:21 +0200
Date: 2007-08-09T20:17:21+02:00	[thread overview]
Message-ID: <RSIui.40$iv.22@news.get2net.dk> (raw)
In-Reply-To: <8y0ckrmscf8e$.1b2tsa5i9w1xp.dlg@40tude.net>

Dmitry A. Kazakov wrote:
> On Thu, 09 Aug 2007 18:06:23 +0200, Poul-Erik Andreasen wrote:
> 
>> How is the best way to make a representation of a
>> function/algorithm wich can bee setup at runtime in Ada.
>>
>> Let say i have for instans a function/algorithm looking like this
>>
>> F(x,y,z) = (3x+25**y)/z
>>
>> This will ofcource require a parser to do the setup, that I can handle.
>> But what will bee the best structure for such generalised function.
> 
> You have to decide whether you want native or interpretable code. The
> former could be a little bit complex. The latter is much simpler, it could
> be some sort of reverse polish notation.
> 
>> I am thinking about some base functions and a tree struture with some
>> access to function variables. Anyone with a better idea?
> 
> Tree is only needed if you wanted a full blown compiler with some complex
> semantic analysis phase. In your case simple stack would suffice:
> 
> 3, x, *, 25, y, **, +, z, /

This is just an simplified example, things will bee a lot more
complicated
> 
> Operands can be kept in a separate storage, organized, again as a stack,
> maybe split into several stacks one per operand's type/size. If you know
> the element size, stack could be implemented more efficiently. Access to
> function for operators is OK, if you don't need to store or else marshal
> the code. Otherwise you would need OP-codes instead.
> 
>> Due to peformance consideration i cannot let the parser calculate the 
>> result imidialty.
> 
> Yes, you parse into interpretable code as most interpreters do. You can
> take a look at examples:
> 
> http://www.dmitry-kazakov.de/ada/components.htm#Parsers_etc
> 
> Where they evaluate an expression or generate a parsing tree for it, you
> just generate the code as above by pushing the operand or operation on the
> stack(s). Interpretation is trivial: if an operand then push it onto the
> working stack (or a reference to the operand), if an operation, call to it,
> pop all its n operands from the working stack,  push the result back,
> repeat ad infinitum.
> 

Thanks, I will take a look at that.


Poul-Erik



  reply	other threads:[~2007-08-09 18:17 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-09 16:06 Dynamic functions Poul-Erik Andreasen
2007-08-09 16:51 ` Georg Bauhaus
2007-08-09 18:20   ` Poul-Erik Andreasen
2007-08-09 17:58 ` Dmitry A. Kazakov
2007-08-09 18:17   ` Poul-Erik Andreasen [this message]
2007-08-10  7:28     ` Dmitry A. Kazakov
2007-08-10  6:54 ` Jacob Sparre Andersen
2007-08-10  7:51   ` Dmitry A. Kazakov
2007-08-10 14:59     ` Poul-Erik Andreasen
2007-08-10 18:56       ` Dmitry A. Kazakov
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox