comp.lang.ada
 help / color / mirror / Atom feed
From: dmitry@elros.cbb-automation.de (Dmitry A. Kazakov)
Subject: Re: Calculator and Operator Precedence
Date: Mon, 25 Feb 2002 09:17:14 GMT
Date: 2002-02-25T09:17:14+00:00	[thread overview]
Message-ID: <3c79fb8b.2460984@News.CIS.DFN.DE> (raw)
In-Reply-To: 3c76780d$1@news.cadence.com

On 22 Feb 2002 17:55:49 +0100, Jean-Marc Bourguet <jm@bourguet.org>
wrote:

>"Steven Deller" <deller@smsail.com> 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



  reply	other threads:[~2002-02-25  9:17 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-02-19 16:26 Calculator and Operator Precedence jon
2002-02-19 17:24 ` Stephen Leake
2002-02-19 20:00 ` Matthew Heaney
2002-02-20  8:03 ` Phil Thornley
2002-02-20 15:28   ` Jon
2002-02-20 15:45     ` John English
2002-02-22 16:10       ` Steven Deller
2002-02-22 16:55         ` Jean-Marc Bourguet
2002-02-25  9:17           ` Dmitry A. Kazakov [this message]
2002-02-22 20:14         ` Vadim Godunko
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox