|converting precedence to productions email@example.com (1996-10-03)|
|Re: converting precedence to productions firstname.lastname@example.org (Brian Bliss) (1996-10-06)|
|Re: converting precedence to productions email@example.com (Neil Faiman) (1996-10-08)|
|Re: converting precedence to productions firstname.lastname@example.org (1996-10-10)|
|From:||email@example.com (Mark Saaltink)|
|Date:||3 Oct 1996 22:58:22 -0400|
I am trying to convert an operator precedence grammar to an
unambiguous grammar without precedence rules. This is usually easy
(e.g. expressions with normal precedence rules), but my grammar has a
low-precedence postfix operator.
The grammar looks something like this:
S ::= n | S and S | S or S | S post | ( S )
with left associativity, and precedence decreasing to the left.
Clearly, "A and B or C" must be parsed as "(A and B) or C".
It is less clear how "A or B post and C" should be parsed; it might
reasonably be "((A or B) post) and C" or "A or ((B post) and C)".
Assuming the former is intended, how can this grammar be transformed to
an unambiguous grammar without precedence rules?
A naive approach defines precedence numbers, and results in
S ::= S1 | S post
S1 ::= S2 | S1 "or" S2
S2 ::= S3 | S2 "and" S3
S3 ::= n | ( S )
which does not work at all here; "A post or B" is rejected.
Return to the
Search the comp.compilers archives again.