<div>Hi,</div>
<div> What I'm trying to do is create a parser so as when I enter say 1+1 it will return Add(Val 1)(Val 1). A couple of questions do I have to state three basic parser. As in item, fail, synbol and then combine them with below. And by the way the one below seems to be all wrong.</div>
<div> </div>
<div> </div>
<div> </div>
<div>parse :: String -> expr<br>parse expr = [(expr,string)]</div>
<div>expr :: Parser value<br>expr = do t <- term<br> do char '+'<br> e <- expr<br> return Add (Val t)(Val e)<br> +++ return t</div>
<div> </div>
<div>(+++) :: Parser a -> Parser a -> Parser a<br>t +++ w inp = case t inp of<br> [] -> w inp<br> [(v,out)] -> [(v,out)]<br></div>
<div> </div>
<div> </div>
<div>This is what I mean by item fail and symbol</div>
<div> </div>
<div>type Parser s a = [s] -> [(a,[s])]<br>item [] = []<br>item (c:cs) = [(c,cs)]</div>
<div>pFail :: Parser s a<br>pFail = \cs -> []</div>
<div>pSymbol :: Eq s => s -> Parser s s<br>pSymbol a (b:bs) |a == b = [(b,bs)]<br> |otherwise = []<br></div>
<div> </div>
<div>I know this is a bit of a mess, but could someone explain where I should start and if I should use any of the code above. Also to point out I want to write the complete parser without using prelude and other built in functions as I will be changing as I go.</div>
<div> </div>
<div>John</div>