on master help sign in
implement simple REPR for Tutorial D interpreter
commitc6898c3e7ebb886fbc18a28499572a47baf4a32a authorAgentM <agentm@themactionfaction.com> dateMon 27 Oct 2014, 21:14 (12 years ago) parent89cf883
4 files changed+24−3
README+4 TutorialDInterpreter.hs+13 project-m36.cabal+3−3 tutd.hs+4
READMEnew file+4
@@ -0,0 +1,4 @@
1+# Project:M36
2+## Relational Algebra Engine
3+
4+Project:M36 implements a relational algebra engine as (mostly) specified by Chris Date.
TutorialDInterpreter.hs+13
@@ -13,6 +13,7 @@ import qualified Data.HashSet as HS
1313import qualified Data.Map as M
1414import Control.Applicative ((<$), (<*), (*>), liftA, liftA2)
1515import Control.Monad.State
16+import System.Console.Readline
1617
1718lexer :: Token.TokenParser ()
1819lexer = Token.makeTokenParser tutD
@@ -126,3 +127,15 @@ example9 = "relA := relation { SNO CHAR }"
126127interpret :: RelVarContext -> String -> (Either RelationalError Relation, RelVarContext)
127128interpret context tutdstring = runState (eval (parseString tutdstring)) context
128129
130+reprLoop :: RelVarContext -> IO ()
131+reprLoop context = do
132+ maybeLine <- readline "TutorialD: "
133+ case maybeLine of
134+ Nothing -> return ()
135+ Just line -> do
136+ addHistory line
137+ case fst (interpret context line) of
138+ Right rel -> putStrLn $ show rel
139+ Left err -> putStrLn $ show err
140+ reprLoop context
141+
project-m36.cabal+3−3
@@ -6,9 +6,9 @@ Homepage: https://github.com/agentm/project-m36
66Category: Relational Algebra
77Cabal-Version: >= 1.2
88
9−Library
10− Build-Depends: base,mtl,containers,unordered-containers,parsec,hashable
11− Exposed-Modules: TutorialDInterpreter
9+Executable tutd
10+ Build-Depends: base,mtl,containers,unordered-containers,parsec,hashable,readline
11+ main-is: tutd.hs
1212
1313Test-Suite test-tutoriald
1414 type: exitcode-stdio-1.0
tutd.hsnew file+4
@@ -0,0 +1,4 @@
1+import TutorialDInterpreter
2+import RelationExpr
3+
4+main = reprLoop dateExamples