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) |
From: | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
Newsgroups: | comp.compilers |
Date: | Fri, 31 May 2013 10:54:00 GMT |
Organization: | Institut fuer Computersprachen, Technische Universitaet Wien |
References: | 13-05-010 13-05-018 13-05-020 |
Keywords: | parse, theory |
Posted-Date: | 31 May 2013 15:16:20 EDT |
jgk@panix.com (Joe keane) writes:
>One person designs a language 'C1' with precedence:
>
> [higher]
> ...
> |
> &
> <, <=, >, <=
> ==, !=
> ...
> [lower]
>
>Some other person designs a language 'C2' with precedence:
>
> [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.
>
>Is there some good way to do this -in the grammar-?
Sure, you don't want | & to asssociate with < <= > >= == != (I find
the remaining associations questionable, but let's stick with your
example). So write the grammar in a way that makes the wanted
associations explicit and does not contain the unwanted associations:
boolexpr: orexpr
| ineqexpr ;
orexpr: orexpr '|' andexpr
| andexpr ;
andexpr: andexpr '&' lower
| lower ;
ineqexpr: eqexpr ineqop eqexpr
| eqexpr ;
eqexpr: lower eqop lower
| lower ;
...
term: '(' highest ')'
| ... ;
(This assumes that a<b<c and a==b==c is not wanted; also, resolving
conflicts is left as an exercise).
- anton
--
M. Anton Ertl
anton@mips.complang.tuwien.ac.at
http://www.complang.tuwien.ac.at/anton/
Return to the
comp.compilers page.
Search the
comp.compilers archives again.