Re: precedence have both ways

glen herrmannsfeldt <gah@ugcs.caltech.edu>
Fri, 31 May 2013 05:10:52 +0000 (UTC)

          From comp.compilers

Related articles
Articles/books that discuss separating the context-free part of a lang costello@mitre.org (Costello, Roger L.) (2013-05-17)
Re: Articles/books that discuss separating the context-free part of a anton@mips.complang.tuwien.ac.at (2013-05-20)
precedence have both ways jgk@panix.com (2013-05-30)
Re: precedence have both ways gah@ugcs.caltech.edu (glen herrmannsfeldt) (2013-05-31)
Re: precedence have both ways anton@mips.complang.tuwien.ac.at (2013-05-31)
| List of all articles for this month |
From: glen herrmannsfeldt <gah@ugcs.caltech.edu>
Newsgroups: comp.compilers
Date: Fri, 31 May 2013 05:10:52 +0000 (UTC)
Organization: Aioe.org NNTP Server
References: 13-05-010 13-05-018 13-05-020
Keywords: parse, errors
Posted-Date: 31 May 2013 15:16:09 EDT

Joe keane <jgk@panix.com> wrote:


(snip)


> This reminds me of a question.


> One person designs a language 'C1' with precedence:
>
> [higher]
> ...
> |
> &
> <, <=, >, <=
> ==, !=
> ...
> [lower]


> Some other person designs a language 'C2' with precedence:


Looks not so far from B, see:


http://cm.bell-labs.com/cm/cs/who/dmr/bref.pdf


> [higher]
> ...
> <, <=, >, <=
> ==, !=
> |
> &
> ...
> [lower]


> They're the same besides that.


> To compromise, they make a new language 'C3' such that a program is
> valid C3 if it is valid C1 and valid C2 -and- both ways mean the same.


Seems easy if you disallow the use of the operators with changed
precedence without appropriate ()'s.


> Is there some good way to do this -in the grammar-?


As above, put the restriction in the grammar.


As I understand it, not having actually ever programmed in B,
(but found the reference manual) B only had the bitwise operators,
and shared them (used them also for) the logical operators.
The had (and have) the appropriate precedence.


When C inherited them from B, and then added the && and || operators,
the previous & and | operators kept their precedence. For actual use
as bitwise operators, such as masks, it would be more convenient if
they had higher precedence. As it is, they pretty much always are
parenthesized. (Easy to forget and generate wrong results.)


-- glen


Post a followup to this message

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