
Hi folks, I have a parser problem. I have a basic calculator program (Graham Hutton's from Nottingham) which contains the following code: -- Define a parser to handle the input expr :: Parser Int expr = do t <- term do symbol "+" e <- expr return (t + e) +++ return t term :: Parser Int term = do f <- factor do symbol "*" e <- expr return (f * t) +++ return f factor :: Parser Int factor = do symbol "(" e <- expr symbol ")" return e +++ natural symbol and natural are defined elsewhere and work fine, but when I compile it I get the error ERROR "C:/HUGS/Calculator.hs":66 - Undefined variable "t" I suspect I'm missing something obvious, but for the life of me I can't see it. Any suggestions? Thanks, Nik (Trying to keep a couple of weeks ahead of her students) Dr Nik Freydís Whitehead University of Akureyri, Iceland ********************************************************************* Having the moral high ground is good. Having the moral high ground and an FGMP-15 is better. *********************************************************************

On Tue, 15 Mar 2005, Nicola Whitehead wrote:
Hi folks,
I have a parser problem. I have a basic calculator program (Graham Hutton's from Nottingham) which contains the following code:
-- Define a parser to handle the input expr :: Parser Int expr = do t <- term do symbol "+" e <- expr return (t + e) +++ return t
I assume that the nested 'do' (before 'symbol') is too much.

On Tue, 15 Mar 2005, Nicola Whitehead wrote: (snip)
term :: Parser Int term = do f <- factor do symbol "*" e <- expr return (f * t) +++ return f (snip)
symbol and natural are defined elsewhere and work fine, but when I compile it I get the error
ERROR "C:/HUGS/Calculator.hs":66 - Undefined variable "t"
I suspect I'm missing something obvious, but for the life of me I can't see it. Any suggestions? (snip)
You are missing something obvious. (-: "t" appears indeed to be undefined in "term". Did you mean "return (f * e)"? Variables (although why they're called that in Haskell I'm not sure) defined with <- in "do" are only in scope later in that "do", not anywhere else. Mark -- Haskell vacancies in Columbus, Ohio, USA: see http://www.aetion.com/jobs.html
participants (4)
-
Henning Thielemann
-
Jules Bean
-
Mark Carroll
-
Nicola Whitehead