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.3 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, REPLYTO_WITHOUT_TO_CC autolearn=no 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:13:25 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!newsfeeds.belnet.be!news.belnet.be!fr.usenet-edu.net!usenet-edu.net!enst!enst.fr!not-for-mail From: "Steven Deller" Newsgroups: comp.lang.ada Subject: RE: Calculator and Operator Precedence Date: Fri, 22 Feb 2002 11:10:15 -0500 Organization: ENST, France Sender: comp.lang.ada-admin@ada.eu.org Message-ID: Reply-To: comp.lang.ada@ada.eu.org NNTP-Posting-Host: marvin.enst.fr Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: avanie.enst.fr 1014394383 68315 137.194.161.2 (22 Feb 2002 16:13:03 GMT) X-Complaints-To: usenet@enst.fr NNTP-Posting-Date: Fri, 22 Feb 2002 16:13:03 +0000 (UTC) Return-Path: X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.2627 Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 In-Reply-To: <3C73C481.6A9235A7@brighton.ac.uk> Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org X-Mailman-Version: 2.0.8 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: comp.lang.ada mail<->news gateway List-Unsubscribe: , Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org Xref: archiver1.google.com comp.lang.ada:20253 Date: 2002-02-22T11:10:15-05:00 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). Since each stack only needs a maximum of 5 entries (because of Ada's left to right evaluation for equal precedence operators) they could have been done with simple arrays (though I used a stack package abstraction). You don't need trees. I thought about using a grammar-based parse (Matthew H's solution), but it has some problems with recognizing where you are in the grammar. Unary operators are the biggest complication. About 50 lines of code. If you can prove you're not doing a student exercise, I'd be glad to send you the sources. Regards, Steve