Re: User friendly compiler-compiler tools [comp.compilers #7671]

anton@complang.tuwien.ac.at (Anton Ertl)
Mon, 23 Oct 1995 22:31:33 GMT

          From comp.compilers

Related articles
User friendly compiler-compiler tools fjh@cs.mu.OZ.AU (1995-10-14)
Re: User friendly compiler-compiler tools [comp.compilers #7671] anton@complang.tuwien.ac.at (1995-10-23)
Re: User friendly compiler-compiler tools fjh@cs.mu.OZ.AU (Fergus Henderson) (1995-11-09)
| List of all articles for this month |
Newsgroups: comp.compilers
From: anton@complang.tuwien.ac.at (Anton Ertl)
Keywords: parse, theory
Organization: Compilers Central
References: 95-10-083
Date: Mon, 23 Oct 1995 22:31:33 GMT

|> [re building expression grammars]
|> > If you think it's necessary, add a few rules for implicit
|> > parenthesizing; when in doubt, require explicit parenthesizing.
|>
|> Current operator-precedence parser generator tools such as yacc make
|> this unnecessarily difficult, because they require a total ordering of
|> operator precedences. Future such tools should allow a partial ordering.


If I remember my math education, partial ordering implies
transitivity. I.e., by stating explicit precedences like


'+' < '='
'=' < '&&'


you would get an implicit precedence


'+' < '&&'


which I did not learn in school and is not intuitive to everyone; in
other word, this precedence is probably not a good idea.


As long as there are only a few independent cases, normal BNF is nice
enough. You can simply add the rules for implicit parenthesizing to
the 'expr' rules in the grammar above.
E.g., for the precedence '=' < '&&' (without the associativity of '&&')


expr: expr1 < expr1 && expr1
expr: expr1 && expr1 < expr1
expr: expr1 < expr1 && expr1 < expr1


We can of course apply some factoring and get


expr: comparison && comparison


comparison: expr1 < expr1
comparison: expr1


As soon as the cases interact, things become more complex: The
classical hierarchical scheme with implied transitive precedences has
to be avoided. There also is the problem of LALR (or LL) conflicts.


- anton
--
M. Anton Ertl
anton@mips.complang.tuwien.ac.at
http://www.complang.tuwien.ac.at/anton/home.html
--


Post a followup to this message

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