minor H98 inconsistency: sections
Tue, 12 Mar 2002 10:00:15 +0000
The following passages differ on the status of (a+b+):
aexp -> ...
| ( expi+1 qop(a,i) ) (left section)
| ( qop(a,i) expi+1 ) (right section)
Syntactic precedence rules apply to sections as follows. (op e) is
legal if and only if (x op e) parses in the same way as (x op (e));
and similarly for (e op). For example, (*a+b) is syntactically invalid,
but (+a*b) and (*(a+b)) are valid. Because (+) is left associative,
(a+b+) is syntactically correct, but (+a+b) is not; the latter may
legally be written as (+(a+b)).
ghc follows the grammar, rejecting (a+b+)
Hugs accepts (op a op' b) and rejects (a op b op') regardless of
associativity and precedence, while nhc accepts them both.
The grammar could be made to match the text by adding two alternatives:
| ( lexpi qop(l,i) ) (left section)
| ( qop(r,i) rexpi ) (right section)
Changing the text to match the grammar seems less attractive.
But the text says more than the revised grammar. For example, it deals
with the expression glitch I mentioned the other week: together with
the disambiguation meta-rule, it implies that the expression
(let x = 10 in x `div`)
is invalid, because
let x = 10 in x `div` z
doesn't parse as (let x = 10 in x) `div` z
(might be worth adding this as an example)
but it's no help with SimonM's example
let x = 10 in x == x == True