diff options
| author | bringert <bringert@cs.chalmers.se> | 2006-12-22 13:43:32 +0000 |
|---|---|---|
| committer | bringert <bringert@cs.chalmers.se> | 2006-12-22 13:43:32 +0000 |
| commit | 7abd4c00a225a9a61c1207617211e846464262d2 (patch) | |
| tree | 0efaa13f54782339bfcfb46caebffeed848357da /src/tools/c/GFCC/Test.hs | |
| parent | a335b29c0a85ea81ee1017f18dd6f2595d2a5227 (diff) | |
Added gfcc2c to GF repo.
Diffstat (limited to 'src/tools/c/GFCC/Test.hs')
| -rw-r--r-- | src/tools/c/GFCC/Test.hs | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/tools/c/GFCC/Test.hs b/src/tools/c/GFCC/Test.hs new file mode 100644 index 000000000..e3c3bcc40 --- /dev/null +++ b/src/tools/c/GFCC/Test.hs @@ -0,0 +1,58 @@ +-- automatically generated by BNF Converter +module Main where + + +import IO ( stdin, hGetContents ) +import System ( getArgs, getProgName ) + +import GFCC.Lex +import GFCC.Par +import GFCC.Skel +import GFCC.Print +import GFCC.Abs + + + + +import GFCC.ErrM + +type ParseFun a = [Token] -> Err a + +myLLexer = myLexer + +type Verbosity = Int + +putStrV :: Verbosity -> String -> IO () +putStrV v s = if v > 1 then putStrLn s else return () + +runFile :: (Print a, Show a) => Verbosity -> ParseFun a -> FilePath -> IO () +runFile v p f = putStrLn f >> readFile f >>= run v p + +run :: (Print a, Show a) => Verbosity -> ParseFun a -> String -> IO () +run v p s = let ts = myLLexer s in case p ts of + Bad s -> do putStrLn "\nParse Failed...\n" + putStrV v "Tokens:" + putStrV v $ show ts + putStrLn s + Ok tree -> do putStrLn "\nParse Successful!" + showTree v tree + + + +showTree :: (Show a, Print a) => Int -> a -> IO () +showTree v tree + = do + putStrV v $ "\n[Abstract Syntax]\n\n" ++ show tree + putStrV v $ "\n[Linearized tree]\n\n" ++ printTree tree + +main :: IO () +main = do args <- getArgs + case args of + [] -> hGetContents stdin >>= run 2 pGrammar + "-s":fs -> mapM_ (runFile 0 pGrammar) fs + fs -> mapM_ (runFile 2 pGrammar) fs + + + + + |
