
Hi Norbert, Francesco,
Thanks. Just an stupid mistake when I change the code. It is actually correct.
Thanks for all your help.
--m00nlight
在2015年04月13 16时29分, "Norbert Melzer"
Dear Haskellers,
I have tried the "while language parser" tutorial on haskellwiki, but I encounter an problem I can not understand here, The following is the code:
So it seems that the order of the operator will affect the parse result. What's the problem with my code? How can I make my program to produce consistent parse result.
Checking the documentation for OperatorTable [1] (the first argument to buildExpressionParser), it seems it is working as expected: An OperatorTable s u m a is a list of Operator s u m a lists. The list is ordered in descending precedence. All operators in one list have the same precedence (but may have a different associativity). I think you can take advantage of the fact that OperatorTable is /a list of lists/, hence aOperators = [ [Prefix (reservedOp "-" >> return (Neg ))] , [Infix (reservedOp "/" >> return (ABinary Divide )) AssocLeft, Infix (reservedOp "*" >> return (ABinary Multiply )) AssocLeft] , [Infix (reservedOp "+" >> return (ABinary Add )) AssocLeft] , [Infix (reservedOp "-" >> return (ABinary Subtract )) AssocLeft] ] should do the trick (try swapping the elements in the second list. Will this do? [1] http://hackage.haskell.org/package/parsec-3.0.0/docs/Text-Parsec-Expr.html#t... _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners