Operator precedence and associativity with Polyparse

Hi, Can someone provide guidance on how handle operator precedence and associativity with Polyparse? Thanks in advance. -Tom

On 26 October 2011 06:37, Tom Hawkins
Hi,
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". -- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com IvanMiljenovic.wordpress.com

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

On 26 October 2011 10:49, 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.
There's nothing like that for PolyParse: it has a much smaller set of combinators than Parsec, which I for one prefer because I don't have to worry about behaviour of existing combinators being different than what I want/need (as it stands, I already use a custom version of bracket from polyparse). -- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com IvanMiljenovic.wordpress.com

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
participants (3)
-
Christian Maeder
-
Ivan Lazar Miljenovic
-
Tom Hawkins