-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from nLatt/22-implement-an-interactive-mode-fo…
…r-the-scheme-interpreter [Fix] add patterns matching
- Loading branch information
Showing
2 changed files
with
58 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
module Main where | ||
|
||
-- Our modules | ||
import Parsing | ||
import Parsing.Token | ||
import Parsing.Cpt | ||
import Parsing.Ast | ||
import Parsing.Args | ||
import System.Console.GetOpt | ||
import Exec | ||
|
||
import System.Environment | ||
import System.Exit | ||
import Data.Maybe (fromMaybe) | ||
|
||
getFileName :: [String] -> Maybe FilePath -> String | ||
getFileName [] b = fromMaybe "stdin" b | ||
getFileName (x:xs) b = x | ||
|
||
runFile :: String -> IO () | ||
runFile filename = do | ||
-- Tokenize | ||
tokens <- tokenizeFile filename | ||
|
||
-- Parse CPT | ||
let cpt = parseTokenList tokens | ||
|
||
-- Parse AST | ||
let ast = parseExprList cpt | ||
|
||
-- Run | ||
run ast | ||
|
||
return () | ||
|
||
|
||
main :: IO () | ||
main = do | ||
-- Parsing arguments | ||
(res, fls) <- getArgs >>= parse | ||
|
||
let fileName = getFileName fls (file res) | ||
print ("Execute file: " ++ fileName) | ||
if (==) fileName "stdin" | ||
then exitSuccess -- interactive | ||
else runFile fileName -- normal |