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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham 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!news4.google.com!feeder3.cambrium.nl!feeder1.cambrium.nl!feed.tweaknews.nl!tudelft.nl!binfeed2.tudelft.nl!news.astraweb.com!newsrouter-eu.astraweb.com!newsfeed101.telia.com!nf02.dk.telia.net!130.227.3.89.MISMATCH!newsfeed1.uni2.dk!news.get2net.dk.POSTED!53ab2750!not-for-mail From: Poul-Erik Andreasen User-Agent: Icedove 1.5.0.9 (X11/20061220) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Dynamic functions References: <46bb3919$0$19890$edfadb0f@dread11.news.tele.dk> <8y0ckrmscf8e$.1b2tsa5i9w1xp.dlg@40tude.net> In-Reply-To: <8y0ckrmscf8e$.1b2tsa5i9w1xp.dlg@40tude.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Thu, 09 Aug 2007 20:17:21 +0200 NNTP-Posting-Host: 213.237.11.74 X-Complaints-To: abuse-dk@tele2.com X-Trace: news.get2net.dk 1186683441 213.237.11.74 (Thu, 09 Aug 2007 20:17:21 CEST) NNTP-Posting-Date: Thu, 09 Aug 2007 20:17:21 CEST Organization: Tele2 Internet Kunde Xref: g2news2.google.com comp.lang.ada:1382 Date: 2007-08-09T20:17:21+02:00 List-Id: 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