data Expr = ExprNum double - constant | Express String - Variables ExprAdd Expr Expr | ExprSub Expr Expr | ExprNeg Expr - Single '-' operator | Xpram Xp Express | Find ExprDiv Expr Expr Show This is my defined user data type. I want to handle arithmetic expressions such as (2 + 3 * 4 - x) buildExpression using the above data type without using the parser. What can i do
Please help me. It should handle operator precedence.
After the
suppose that we want to create a addsub level parser. We have to say that (returning the right value to the actual ignore and just focusing on the raw paras) want to do
addsub MULDIV => & Gt; & Gt; & Gt; "+" oneof MULDIVThis does not really work. But we can become the left factor and
= addsub MULDIV> & Gt; Addsub 'addsub' = $ oneof many "+ -" & gt; & Gt; MULDIVtowhere we have a parser for the value of
MULDIVis just multiplication and division which you can write in a similar way.That is, instead of using grammar
= addsub addsub (+ -) MULDIV | MULDIV>We use a bit more complex, but actually usable by Parsec:
addedub = MULDIV addsub 'addsub = (+ -) MULDIV addsub '| Nothing.Which certainly we can refactor the latter in a
manywhich gives us a list of expressions that we must add. Then you do whatever you want to do that form, como(add a1 (add A2 (a3 pairs))).
Comments
Post a Comment