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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d5ed2292349acc76 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-02-25 01:17:16 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!newshunter!cosy.sbg.ac.at!fu-berlin.de!uni-berlin.de!tar-alcarin.cbb-automation.DE!not-for-mail From: dmitry@elros.cbb-automation.de (Dmitry A. Kazakov) Newsgroups: comp.lang.ada Subject: Re: Calculator and Operator Precedence Date: Mon, 25 Feb 2002 09:17:14 GMT Message-ID: <3c79fb8b.2460984@News.CIS.DFN.DE> References: <3c76780d$1@news.cadence.com> NNTP-Posting-Host: tar-alcarin.cbb-automation.de (212.79.194.111) X-Trace: fu-berlin.de 1014628634 6507959 212.79.194.111 (16 [77047]) X-Newsreader: Forte Free Agent 1.21/32.243 Xref: archiver1.google.com comp.lang.ada:20351 Date: 2002-02-25T09:17:14+00:00 List-Id: On 22 Feb 2002 17:55:49 +0100, Jean-Marc Bourguet wrote: >"Steven Deller" writes: > >> Interestingly, I just cobbled together Ada code to parse arbitrary Ada >> expressions consisting of just operators, parentheses, and literals (I'm >> probably going to make it handle type conversions as well). >> >> It uses two stacks (one for operands, one for operators), and recursion >> (on parentheses). > >Why do you need recursion? Parentheses can be handled with the two >stacks, pushing opening parenthese on the operator stack and applaying >operators till a openening parenthese is on TOS when seeing a close >parenthese. Yes, this technique works perfectly with prefix, postfix operations as well as function calls and array indexing. No recursion is necessary. Though kind of pattern matching might be useful for comment detection. >BTW, This parsing technique can be extented (see weak operator >precedence in the litterature) and has been used quite a lot before >LALR grammar where showed to be usefull. It is still in use.(:-)) I have used it for parsing measurement unit expressions, which have prefix, dyadic and postfix operations. Regards, Dmitry Kazakov