diff options
| author | aarne <unknown> | 2004-12-20 07:57:05 +0000 |
|---|---|---|
| committer | aarne <unknown> | 2004-12-20 07:57:05 +0000 |
| commit | 6e1f41b26af8154033fda32c573aba56d7cb89fb (patch) | |
| tree | cdfd17dd3a1444f3a921cadc6d0a141178767819 /examples/gfcc/compiler/LexImperC.hs | |
| parent | 8caa3ed737900c0fc004b24720f909244d17dd59 (diff) | |
gfcc in Types
Diffstat (limited to 'examples/gfcc/compiler/LexImperC.hs')
| -rw-r--r-- | examples/gfcc/compiler/LexImperC.hs | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/examples/gfcc/compiler/LexImperC.hs b/examples/gfcc/compiler/LexImperC.hs index d030a8cd5..ceec89d25 100644 --- a/examples/gfcc/compiler/LexImperC.hs +++ b/examples/gfcc/compiler/LexImperC.hs @@ -60,20 +60,18 @@ prToken t = case t of _ -> show t +data BTree = N | B String Tok BTree BTree deriving (Show) + eitherResIdent :: (String -> Tok) -> String -> Tok -eitherResIdent tv s = if isResWord s then (TS s) else (tv s) where - isResWord s = isInTree s $ - B "int" (B "float" (B "else" N N) (B "if" N N)) (B "return" (B "printf" N N) (B "while" N N)) - -data BTree = N | B String BTree BTree deriving (Show) - -isInTree :: String -> BTree -> Bool -isInTree x tree = case tree of - N -> False - B a left right - | x < a -> isInTree x left - | x > a -> isInTree x right - | x == a -> True +eitherResIdent tv s = treeFind resWords + where + treeFind N = tv s + treeFind (B a t left right) | s < a = treeFind left + | s > a = treeFind right + | s == a = t + +resWords = b "int" (b "float" (b "else" N N) (b "if" N N)) (b "return" (b "printf" N N) (b "while" N N)) + where b s = B s (TS s) unescapeInitTail :: String -> String unescapeInitTail = unesc . tail where |
