From 6e1f41b26af8154033fda32c573aba56d7cb89fb Mon Sep 17 00:00:00 2001 From: aarne Date: Mon, 20 Dec 2004 07:57:05 +0000 Subject: gfcc in Types --- examples/gfcc/compiler/LexImperC.hs | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'examples/gfcc/compiler/LexImperC.hs') 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 -- cgit v1.2.3