[Haskell-cafe] Operator precedence and associativity with Polyparse
Christian Maeder
Christian.Maeder at dfki.de
Wed Oct 26 15:09:09 CEST 2011
Am 26.10.2011 01:49, schrieb Tom Hawkins:
>>> Can someone provide guidance on how handle operator precedence and
>>> associativity with Polyparse?
>>
>> Do you mean parsing something like "1 + 2 * 3" ? I don't think
>> there's any real difference in using Polyparse vs Parsec for this,
>> except for doing "p `orElse` q" rather than "try p<|> q".
>
> Actually, I was looking for something equivalent to
> Text.ParserCombinators.Parsec.Expr.buildExpressionParser. I suppose I
> should learn how Parsec implements this under the hood.
I would do it as described under chainl1 in
http://hackage.haskell.org/packages/archive/parsec2/1.0.0/doc/html/Text-ParserCombinators-Parsec-Combinator.html
I believe Parsec.Expr cannot handle a prefix operator (i.e. unary minus)
properly, that has lower precedence than an infix operator (i.e. "^"
power). If it can parse "-x^2" as "-(x^2)" then if cannot parse "x^ -2"
as "x^(-2)".
Cheers Christian
>
> -Tom
More information about the Haskell-Cafe
mailing list