Note that there are some explanatory texts on larger screens.

plurals
  1. POHaskell recursive problem, tiny parser. A few things
    primarykey
    data
    text
    <pre><code>data Expr = Var Char | Tall Int | Sum Expr Expr | Mult Expr Expr | Neg Expr | Let Expr Expr Expr deriving(Eq, Show) </code></pre> <p>That is the datatype for <code>Expr</code>, I have a few questions. I'm suppose to parse expressions like <code>*(Expr,Expr)</code> as shown in the datatype definition. However I do have some problems with "creating" a valid <code>Expr</code>. I use pattern matching for recognizing the different things Expr can be. Some more code: </p> <pre><code>parseExpr :: String -&gt; (Expr, String) parseExpr ('*':'(':x:',':y:')':s) = (Mult (parseExpr [x] parseExpr [y]),s) </code></pre> <p>This is not working, obviously. The return type of <code>parseExpr</code> is to return the rest of the expression that is to be parsed an a portion of the parsed code as an <code>Expr</code>. The right side of this code is the problem. I can't make a valid <code>Expr</code>. The function is suppose to call it self recursively until the problem is solved. </p> <p>ANOTHER problem is that I don't know how to do the pattern matching against <code>Var</code> and <code>Tall</code>. How can I check that <code>Var</code> is an uppercase character between A-Z and that <code>Tall</code> is 0-9 and return it as a valid <code>Expr</code>? </p> <p>Generally I can just look at a few parts of the string to understand what part of <code>Expr</code> I'm dealing with. </p> <pre><code>Input like: parseProg "let X be 9 in *(X , 2)" Would spit out: Let (Var 'X') (Tall 9) (Mult (Var 'X') (Tall 2)) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload