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 12:16:04 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!logbridge.uoregon.edu!isdnet!enst!enst.fr!not-for-mail From: "Vadim Godunko" Newsgroups: comp.lang.ada Subject: Re: Calculator and Operator Precedence Date: Fri, 22 Feb 2002 23:14:20 +0300 Organization: ENST, France Sender: comp.lang.ada-admin@ada.eu.org Message-ID: References: Reply-To: comp.lang.ada@ada.eu.org NNTP-Posting-Host: marvin.enst.fr Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Trace: avanie.enst.fr 1014408962 75531 137.194.161.2 (22 Feb 2002 20:16:02 GMT) X-Complaints-To: usenet@enst.fr NNTP-Posting-Date: Fri, 22 Feb 2002 20:16:02 +0000 (UTC) Return-Path: X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 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:20262 Date: 2002-02-22T23:14:20+03:00 Hello, Please send me those sources. Very intresting. Regards, Vadim ----- Original Message ----- From: "Steven Deller" Newsgroups: comp.lang.ada Sent: Friday, February 22, 2002 7:10 PM Subject: RE: Calculator and Operator Precedence > 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 >