[Haskell-cafe] a novice Alex question

2006-08-25 Thread Xiong Yingfei
Hi,

I am trying out Alex. I copied the calculator specification file from Alex's 
official document and changed the wrapper type from basic to monad. 
However, after I generated the .hs file from the lexical specification and 
compiled the .hs file, I got the message Variable not in scope: `alexEOF'. 
I cannot find explanation about this 'alexEOF' function in the document. Can 
any body be kindly enough to tell me what this function is? Should I write it 
myself or not? My lexical code is listed as the below. Thanks a lot.


{
module Lex where

}

%wrapper monad

$digit = 0-9   -- digits
$alpha = [a-zA-Z]  -- alphabetic characters

tokens :-

  $white+;
  --.*;
  let { \s - Let }
  in { \s - In }
  $digit+{ \s - Int (read s) }
  [\=\+\-\*\/\(\)]   { \s - Sym (head s) }
  $alpha [$alpha $digit \_ \']*  { \s - Var s }

{
-- Each action has type :: String - Token

-- The token type:
data Token =
 Let   |
 In|
 Sym Char |
 Var String |
 Int Int
 deriving (Eq,Show)
}

--
Xiong, Yingfei (熊英飞)
Ph.D. Student
Institute of Software
School of Electronics Engineering and Computer Science
Peking University
Beijing, 100871, PRC.
Web: http://xiong.yingfei.googlepages.com___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] question on traversing syntax tree

2006-08-24 Thread Xiong Yingfei
I am writing a compiler using Haskell. After the compiler parses program, the 
program is stored into an syntax tree stucture defined blew:

..
data Exp 
  = Plus Exp Term 
  | Minus Exp Term 
  | Term Term
  deriving Show

data Term 
  = Times Term Factor 
  | Div Term Factor 
  | Factor Factor
  deriving Show
..

This is just part of the definition. The full tree contains much more 
definition than this. Now I want to adjust the syntax-tree. However, I don't 
need to adjust all the data types, but a small subset of the syntax tree. e.g. 
I might adjust the Times data like the following, but not modify the rest of 
the syntax tree:
transformTerm (Times t f) = Times t (FactorInt 100)

However, in order to apply the modification like this, I have to write a series 
of function to traverse the tree until I get to the Term data type. e.g. I have 
to define:
transformExp (Plus e t) = Plus (transformExp e) (transformTerm t)
transformExp (Minus e t) = Minus (transformExp e)(transformTerm t)
transformTerm (Term t) = ...

This is tedious and error-prone. I want to know if there some means in Haskell 
to write a single generic function to traverse the syntax tree and only stop 
on the Term data type. Can anyone tell me something about it? Thanks a lot.

--
Xiong, Yingfei (熊英飞)
Ph.D. Student
Institute of Software
School of Electronics Engineering and Computer Science
Peking University
Beijing, 100871, PRC.
Web: http://xiong.yingfei.googlepages.com___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe