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-22 08:55:57 PST Newsgroups: comp.lang.ada Subject: Re: Calculator and Operator Precedence References: From: Jean-Marc Bourguet Date: 22 Feb 2002 17:55:49 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii NNTP-Posting-Host: cdssoph29.cadence.com Message-ID: <3c76780d$1@news.cadence.com> X-Trace: news.cadence.com 1014396941 cdssoph29.cadence.com (22 Feb 2002 08:55:41 -0800) Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.online.be!ams.uu.net!nyc.uu.net!news.cadence.com Xref: archiver1.google.com comp.lang.ada:20258 Date: 2002-02-22T17:55:49+01:00 List-Id: "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. 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. -- Jean-Marc