Peculiarity in Ada grammar

clsi!graham@uunet.UU.NET (Paul Graham)
Wed, 19 Jan 1994 17:18:05 GMT

          From comp.compilers

Related articles
Peculiarity in Ada grammar clsi!graham@uunet.UU.NET (1994-01-19)
Re: Peculiarity in Ada grammar nebbe@lglsun.epfl.ch (1994-01-20)
Re: Peculiarity in Ada grammar burley@mole.gnu.ai.mit.edu (1994-01-20)
| List of all articles for this month |
Newsgroups: comp.compilers
From: clsi!graham@uunet.UU.NET (Paul Graham)
Keywords: Ada, parse, design
Organization: Compilers Central
Date: Wed, 19 Jan 1994 17:18:05 GMT

I was reading in Aho and Ullman about operator precedence parsing. The
book said that operator precedence works well for grammars in which each
operator has a fixed precedence, but breaks down (or at least becomese
more complicated) when operators have different precedence levels in
different contexts.


In C, minus has two different precedences, one for the unary form and one
for the binary form. Unary minus is at the same precedence level as other
unary operators such as logical negation and bitwise negation, while
binary minus is at the level of binary plus.


Ada has only one precedence for minus, at the cost of giving unary minus
lower precedence than multiplication operators. This has the unintuitive
effect of making
-5 mod 3 = -(5 mod 3)
while
-5 mod 3 /= (-5) mod 3


I wonder if Ada's expression grammar was designed with operator precedence
parsing in mind? Otherwise, how can the unintuitive precedence of unary
minus be explained?


Paul
--
Paul Graham, Compass Design Automation, Inc.
graham@clsi.com OR support@clsi.com 410-992-5700
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.