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,53a571639ed0bc5a X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!storethat.news.telefonica.de!telefonica.de!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Dynamic functions 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: <46bb3919$0$19890$edfadb0f@dread11.news.tele.dk> Date: Thu, 9 Aug 2007 19:58:27 +0200 Message-ID: <8y0ckrmscf8e$.1b2tsa5i9w1xp.dlg@40tude.net> NNTP-Posting-Date: 09 Aug 2007 19:58:25 CEST NNTP-Posting-Host: 29804d37.newsspool4.arcor-online.net X-Trace: DXC=O3[;`RLE3FTKgn7V`7D X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:1381 Date: 2007-08-09T19:58:25+02:00 List-Id: 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, / 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. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de