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!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!inka.de!rz.uni-karlsruhe.de!news.belwue.de!news-stu1.dfn.de!news-fra1.dfn.de!npeer.de.kpn-eurorings.net!npeer-ng1.kpn.DE!newsfeed.arcor.de!newsspool4.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> <8d9b43fa-05a1-4024-bbd3-ddf276478748@40g2000prx.googlegroups.com> Date: Thu, 16 Oct 2008 10:14:28 +0200 Message-ID: <1pi77s16bxnp7.1xl804u3qtcbb$.dlg@40tude.net> NNTP-Posting-Date: 16 Oct 2008 10:14:28 CEST NNTP-Posting-Host: 04f738d2.newsspool4.arcor-online.net X-Trace: DXC=c7emnDm37]:nBOkdL^Lo7>4IUK7enW;^6ZC`4IXm65S@:3>?6jOTgWkB831 X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:2406 Date: 2008-10-16T10:14:28+02:00 List-Id: On Wed, 15 Oct 2008 08:22:36 -0700 (PDT), Adam Beneschan wrote: > Although it isn't always possible, I definitely prefer to set things > up in an array or some sort of data structure when possible, rather > than to rely on a 67-branch IF statement or even a CASE statement. This is what I do in my parsers. I use an enumeration type for the operations. For example: type Operations is ( Add, Sub, Mul, Div, Pow, -- Infix operators Abs_Value, Plus, Minus, -- Prefix operators Left_Bracket, Right_Bracket -- Brackets ); When the parser pops an operation from the stack of operations it calls the corresponding primitive operation (of the stack type) that switches over Operations value using plain case statement. I don't define unary and binary operations separately, because with subprograms supported the number of arguments will vary anyway. Then even for +, I prefer to allow the parser to coalesce expressions like "+" ("+" (A, B), C) into "+" (A, B, C) -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de