amrun 0.0.0.6 → 0.0.0.7
raw patch · 2 files changed
+5/−3 lines, 2 files
Files
- amrun.cabal +1/−1
- src/amrun.hs +4/−2
amrun.cabal view
@@ -1,5 +1,5 @@ Name: amrun-Version: 0.0.0.6+Version: 0.0.0.7 Synopsis: Interpreter for AM Description: The package contains an interpreter for the AM-Language that is introduced in the basic programming course \"Algorithmisches Denken und imperative Programmierung\" (WS 2011/12 and later) at the University of Bonn. License: GPL
src/amrun.hs view
@@ -17,6 +17,7 @@ | STORE Int | LIT Int | ADD | MUL | SUB | DIV | MOD | LT | EQ | NE | GT | LE | GE | JMP Int | JMC Int+ | NOP deriving (Show, Eq) @@ -59,6 +60,7 @@ step (JMC e) (m,0:d',h,inp,out) = (e,d',h,inp,out) step (JMC e) (m,1:d',h,inp,out) = (m+1,d',h,inp,out) step (JMC _) (m,_:_,_,_,_) = error $ "In Programmzeile " ++ show m ++ ", versuchter JMC, obwohl Datenkellerspitze weder 0 noch 1."+step NOP (m,d,h,inp,out) = (m+1,d,h,inp,out) step _ (m,[],_,_,_) = error $ "In Programmzeile " ++ show m ++ ", Versuch auf leeren Datenkeller zuzugreifen." step _ (m,[_],_,_,_) =@@ -74,7 +76,6 @@ | a>n = (n,c):(a,b):h update [] n c = [(n,c)] - run :: [Command] -> (Int,[Int],[(Int,Int)],[Int],[Int]) -> [(Int,[Int],[(Int,Int)],[Int],[Int])] run prog conf = if valid prog conf then conf:(run prog (next prog conf))@@ -153,7 +154,7 @@ arg <- (pcParser <?> "command argument") if cmd == "LIT" || cmd == "JMC" || cmd == "JMP" then return (c (sign*arg))- else (if arg == 0 then unexpected (cmd ++ " does not take 0 as argument.") else return (c arg))+ else return (c arg) Nothing -> unexpected (cmd ++ " is not a command.") } where@@ -170,6 +171,7 @@ "GT" -> Just GT "LE" -> Just LE "GE" -> Just GE+ "NOP" -> Just NOP _ -> Nothing readCmd' cmd = case cmd of "READ" -> Just READ