Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.compilers > #909
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Newsgroups | comp.compilers |
| Subject | Re: precedence have both ways |
| Date | 2013-05-31 10:54 +0000 |
| Organization | Institut fuer Computersprachen, Technische Universitaet Wien |
| Message-ID | <13-05-023@comp.compilers> (permalink) |
| References | <13-05-010@comp.compilers> <13-05-018@comp.compilers> <13-05-020@comp.compilers> |
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/
Back to comp.compilers | Previous | Next — Previous in thread | Find similar | Unroll thread
Articles/books that discuss separating the context-free part of a language from the context-sensitive part? "Costello, Roger L." <costello@mitre.org> - 2013-05-17 20:57 +0000
Re: Articles/books that discuss separating the context-free part of a language from the context-sensitive part? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-05-18 00:18 +0000
Re: Articles/books that discuss separating the context-free part of a language from the context-sensitive part? Gene Wirchenko <genew@telus.net> - 2013-05-19 18:02 -0700
Re: Articles/books that discuss separating the context-free part of a language from the context-sensitive part? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-05-20 03:17 +0000
Re: Articles/books that discuss separating the context-free part of a language from the context-sensitive part? Aleksey Demakov <ademakov@gmail.com> - 2013-05-18 16:52 +0400
Re: Articles/books that discuss separating the context-free part of a language from the context-sensitive part? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-05-20 10:53 +0000
Re: Articles/books that discuss separating the context-free part of a language from the context-sensitive part? Gene Wirchenko <genew@telus.net> - 2013-05-20 23:24 -0700
precedence have both ways jgk@panix.com (Joe keane) - 2013-05-30 23:21 -0400
Re: precedence have both ways glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-05-31 05:10 +0000
Re: precedence have both ways anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-05-31 10:54 +0000
csiph-web