Upgrade is finished. Everything should be working now.

Commit bd9a889d authored by Tadej Borovšak's avatar Tadej Borovšak
Browse files

Start of homework

parent 9376e0e6
module Imp_AbsSyntax where module Imp_AbsSyntax where
-- Haskell datatypes representing abstract syntax of expressions and commands -- Haskell datatypes representing abstract syntax of expressions and commands
-- arithmetic expressions -- arithmetic expressions
data AExp = data AExp =
Loc String | Loc String |
...@@ -23,5 +23,3 @@ data Com = ...@@ -23,5 +23,3 @@ data Com =
Skip | Skip |
While (BExp, Com) While (BExp, Com)
deriving Show deriving Show
module Imp_Evaluator where module Imp_Evaluator where
import Imp_AbsSyntax import Imp_AbsSyntax
import Imp_State import Imp_State
......
...@@ -4,11 +4,11 @@ import Imp_Parse ...@@ -4,11 +4,11 @@ import Imp_Parse
import Imp_State import Imp_State
import Imp_Evaluator import Imp_Evaluator
-- runImp "file.imp" s -- runImp "file.imp" s
-- --
-- lexes and parses the Imp program text in file.imp and then -- lexes and parses the Imp program text in file.imp and then
-- executes it starting in state s -- executes it starting in state s
runImp filename s = do runImp filename s = do
progtext <- readFile filename progtext <- readFile filename
let lexed = imp_lex progtext let lexed = imp_lex progtext
......
-- vim: set syntax=alex autoindent
{module Imp_Lex where } {module Imp_Lex where }
...@@ -6,33 +7,37 @@ ...@@ -6,33 +7,37 @@
-- character classes -- character classes
$digit = [0-9] $digit = [0-9]
$lower = [a-z] $alpha = [A-Za-z]
$upper = [A-Z]
:- :-
-- lexical classes $white+ ; -- whitespace
\( | \) {\s -> SCOPE s} -- scope
-- \; {\s -> DELIM} -- command delimiter
-- [[IMPLEMENT YOUR LEXICAL CLASSES HERE]] \+ | \- | \* {\s -> OP s} -- arithmetic ops
-- \=\= | \< {\s -> OP s} -- boolean ops
\:\= {\s -> ASSIGN} -- assignment
if | then | else {\s -> KEYWORD s} -- if command
while | do {\s -> KEYWORD s} -- while command
skip {\s -> KEYWORD s} -- skip command
True | False {\s -> BOOL $ read s} -- boolean literals
$digit+ {\s -> NUM $ read s} -- numbers
$alpha [$alpha $digit \_]* {\s -> LOC s} -- locations
{ {
-- The Token type - the action for each lexical class has type String -> Token -- The Token type - the action for each lexical class has type String -> Token
data Token = data Token = SCOPE String
-- | DELIM
-- [[IMPLEMENT YOUR Token TYPE HERE]] | OP String
-- | ASSIGN
deriving Show | KEYWORD String
| BOOL Bool
-- The lexer implements a function | NUM Integer
-- | LOC String
-- imp_lex :: String -> [Token] | INVALID
-- deriving Show
-- which converts a string containing Imp program text into a list of tokens
imp_lex = alexScanTokens imp_lex = alexScanTokens
......
-- vim: set syntax=happy
{module Imp_Parse where {module Imp_Parse where
import Imp_Lex import Imp_Lex
import Imp_AbsSyntax import Imp_AbsSyntax
...@@ -9,7 +11,7 @@ import Imp_AbsSyntax ...@@ -9,7 +11,7 @@ import Imp_AbsSyntax
-- --
-- that converts a list of tokens to the abstract syntax tree of a command -- that converts a list of tokens to the abstract syntax tree of a command
%name imp_parse Com %name imp_parse Com
%tokentype { Token } %tokentype { Token }
%error { parseError } %error { parseError }
...@@ -26,7 +28,7 @@ import Imp_AbsSyntax ...@@ -26,7 +28,7 @@ import Imp_AbsSyntax
-- --
-- [[MAKE PRECEDENCE AND ASSOCIATIVITY DECLARATIONS HERE]] -- [[MAKE PRECEDENCE AND ASSOCIATIVITY DECLARATIONS HERE]]
-- --
%% %%
-- the grammar -- the grammar
...@@ -34,9 +36,9 @@ import Imp_AbsSyntax ...@@ -34,9 +36,9 @@ import Imp_AbsSyntax
-- --
-- [[DEFINE YOUR GRAMMAR AND ITS ACTIONS HERE]] -- [[DEFINE YOUR GRAMMAR AND ITS ACTIONS HERE]]
-- --
{ {
parseError :: [Token] -> a parseError :: [Token] -> a
parseError _ = error "Imp parse error" parseError _ = error "Imp parse error"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment