summaryrefslogtreecommitdiff
path: root/examples/gfcc/compiler
diff options
context:
space:
mode:
authoraarne <unknown>2004-11-09 18:12:51 +0000
committeraarne <unknown>2004-11-09 18:12:51 +0000
commitb183a0a7bc6944e9cfbbb240673c9b7387e5ff69 (patch)
treeb5e048f3d133878df03dff8f54ba47ae0cbedee9 /examples/gfcc/compiler
parent12b9b5f3d3efe6e029f0cde1013d5b8b63585116 (diff)
Test.hs
Diffstat (limited to 'examples/gfcc/compiler')
-rw-r--r--examples/gfcc/compiler/ParImperC.hs2
-rw-r--r--examples/gfcc/compiler/TestImperC.hs46
2 files changed, 47 insertions, 1 deletions
diff --git a/examples/gfcc/compiler/ParImperC.hs b/examples/gfcc/compiler/ParImperC.hs
index 7880a1627..c37222bd1 100644
--- a/examples/gfcc/compiler/ParImperC.hs
+++ b/examples/gfcc/compiler/ParImperC.hs
@@ -655,7 +655,7 @@ happyError ts =
myLexer = tokens
{-# LINE 1 "GenericTemplate.hs" #-}
--- $Id: ParImperC.hs,v 1.1 2004/11/08 10:22:38 aarne Exp $
+-- $Id: ParImperC.hs,v 1.2 2004/11/09 19:12:51 aarne Exp $
diff --git a/examples/gfcc/compiler/TestImperC.hs b/examples/gfcc/compiler/TestImperC.hs
new file mode 100644
index 000000000..a32777a5d
--- /dev/null
+++ b/examples/gfcc/compiler/TestImperC.hs
@@ -0,0 +1,46 @@
+-- automatically generated by BNF Converter
+module Main where
+
+
+import Trees
+import Profile
+import IO ( stdin, hGetContents )
+import System ( getArgs, getProgName )
+
+import LexImperC
+import ParImperC
+import ErrM
+
+type ParseFun = [Token] -> Err CFTree
+
+myLLexer = myLexer
+
+runFile :: ParseFun -> FilePath -> IO ()
+runFile p f = readFile f >>= run p
+
+run :: ParseFun -> String -> IO ()
+run p s = do
+ let ts = myLLexer s
+ let etree = p ts
+ case etree of
+ Ok tree -> do
+ case postParse tree of
+ Bad s -> do
+ putStrLn "\nParse Failed... CFTree:\n"
+ putStrLn $ prCFTree tree
+ putStrLn s
+ Ok tree -> do
+ putStrLn "\nParse Successful!"
+ putStrLn $ "\n[Abstract Syntax]\n\n" ++ prt tree
+ Bad s -> do
+ putStrLn s
+ putStrLn "\nParse failed... tokenization:"
+ print ts
+
+main :: IO ()
+main = do args <- getArgs
+ case args of
+ [] -> hGetContents stdin >>= run pProgram
+ [f] -> runFile pProgram f
+ _ -> do progName <- getProgName
+ putStrLn $ progName ++ ": excess arguments."