
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-Pars... 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