On 07/07/2010 15:47, Christian Maeder wrote:
Simon Marlow schrieb:
On 06/07/2010 13:17, Christian Maeder wrote:

http://www.haskell.org/~simonmar/haskell-2010-draft-report-2/haskellch3.html


infixexp →     lexp qop infixexp (infix operator application)
     |     - infixexp           (prefix negation)
     |     lexp

This grammar rule describes a right associative nesting of (any) infix
operators "qop" and prefix negation as binding weaker than any infix.

Thus a parser would create from "- 1 /= 1&&   a" the tree
   "- (1 /= (1&&   a))".

The grammar is non-ambiguous and all you have to do is flatten the
result to apply fixity resolution.  I don't really see how generalising
the grammar would help - the tree still has to be flattened to apply
fixity resolution, and the parser would have to make an arbitrary choice
from one of the possible parses.  Or perhaps I'm missing something here?

An ambiguous grammar (as abstract syntax for expressions) would cover
the tree after fixity resolution, too.

The non-ambiguous grammar only describes a temporarily wrong tree for
fixity resolution.

Yes it does, intentionally. But I see your point, and arguably the current grammar is inconsistent; prefix negation should move to lexp to be consistent with lpat (and to avoid the strange parse you point out above).


I suppose my concern is that if we generalised the grammar, then we would have to also explain why the grammar was ambiguous and that a parser should pick a suitable parse before applying fixity resolution. As you say, it's a presentational point, I'm not against changing it.

Cheers, 
        Simon

_______________________________________________
Haskell-prime mailing list
Haskell-prime@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-prime

Reply via email to