haskell - datatype conversion without using buildExpressionParser -
I am stuck at a point in changing the expression for the user's datatype
I was using biuldExpressionParser
, but I did the following by using simple parser and recursive
openBrace = char '(' CloseBrace :: GenParser char st char Closebrace = char ')' bracketxprod = spaces & gt; & Gt; OpenBrace expr & lt; - Expression parser spaces & gt; & Gt; CloseBrace return expr
bracketExpr
will return the expression entered into my own datatype
To change it into my datatype, If the expression is a number or a variable as follows:
expressionParser = negate1 & lt; | & Gt; Number & lt; | & Gt; Variable - & lt; | & Gt; Add & lt ;? & Gt; "Simple expression" negate1 :: parser xp negate1 = do {char '-'; Ds & lt; - Number; Return (Xprunge (DS)) & lt ;? & Gt; "Disclaimer" variable :: parser express Variable = Do {DS & LT; - many 1 (letter & lt;; & gt; digits); Return (XVVR DS)}
edition, I tried to isolate the expression using sepBy
but I have to face many issues.
If I am unable to proceed from here (Express 1) (Xprp 2)
If you want to write a parser with the connectors Parser, which you need to think first in terms of high-level rules, here is a skeleton parser in Parsec; It does not meets 100% of your needs because all operators are similarities and right-cooperatives, while you may want different bias and left-collaboration. However, this is the basic way to write a parser:
import text. Reader Import Text. Paragraph import data. Client (Digit) - Basic Data Type Data Expr = Op Char Expr XP | N integer derived (show) type parser x = parsec string () x - reverse-sequenced & gt; & Gt ;, bracketed `and 'white-wrench` (<< lt;) :: Moneda M => M X - & gt; Y - & gt; MX MX & lt; & Lt; My = mx & gt; & Gt; = \ X - & gt; My & gt; & Gt; Return x infixel 1 & lt; & Lt; Fielded :: Parser E - & gt; Parser e brackets and e = four '('> '>' white ');' whitespaced :: Parser e - & gt; Parser e whitespace e = space & gt; & Gt; E & lt; & Lt; Space Number :: Parsons Express Number = Do C & LT; - Anof "123456789" - Can be reserved for the Octal / Hexadecimal CS of major 0 - Return of many digits (N (read (C: CS)) Operator :: Parser Expr operator = do e1 & lt; - expr_no_op o & Lt; - whitespaced (oneOf "+ * / -") e2 & lt; - expression returns (op o e1 e2) expr_no_op :: parser expression expr_no_op = whitespaced (try number & lt;; & gt expression expression: expression :: Expression expression: Express expression = whitespaced (try operator | Try & lt; | & gt; Fielded Expressions)
Note that you token (top, only 'number') and then "this
otherwise try ... "syntax, also keep in mind that to prevent operator
Do not take the expression as your first argument otherwise you should loop it into a operator -> expression -> operator
parsing "left factorial "Is called.
Comments
Post a Comment