Students uses old version of Haskell and BNFC, therefore a newer version should be prepended to the PATH before building the project.
export PATH=~/.cabal/bin:/home/students/inf/PUBLIC/MRJP/ghc-8.2.2/bin:$PATH
- Installing dependencies
make deps
- Generating the parser
make grammar
- Compiling the interpreter
make interpreter
Running make
with no subcommand will execute all of the above.
data Var = ... -- variable value
type Loc = ... -- variable location
Used to store the environment - a mapping from an identifier to a location.
import qualified Data.Map as DataMap
type Env = DataMap.Map Ident Loc
Used as a store - a mapping from a location to the actual value. Both functions and variables are stored in the same store.
import qualified Data.Map as DataMap
type Store = DataMap.Map Loc Var
Used to handle runtime errors in the interpreter.
Used to store the environment - a mapping from an identifier to a type.
import qualified Data.Map as DataMap
type Env = DataMap.Map Ident Type
Used to handle runtime errors in the interpreter.
- Main.hs mostly copied from a BNFC generated source code with small tweaks to start the interpreter on a given file.
- Util.hs contains helper functions used in both interpreter and the type checker.
- IInterpreter.hs defines types used in the interpreter.
- TCheck.hs defines types used in the tupe checker.
- IExec.hs implements
exec
function, which execs the given program. - IUtil.hs contains helper functions used in the interpreter.
- TExec.hs implements
execType
function, which runs the type check on the given program. - TUtil.hs contains helper functions used in the type checker.
- MArray.hs implements methods, which can be called on an Array variable:
Append
appends an element at the end of an array.At
returns an element at the given position.Put
inserts an element at the given position to an array.Length
returns the length of an array.
- MError.hs implements methods, which can be called on an Error variable.
HaveOccurred
returns whether an error is not empty.
- MInt.hs implements methods, which can be called on an Int variable.
ToString
converts an integer to its string representation.
- MString.hs implements methods, which can be called on a String variable.
ToInt
converts a string to an integer, if the given string does not represent a decimal number calling this method will result in anRuntimeError
.
- MTuple.hs implements methods, which can be called on a Tuple variable.
Extract
extracts a single value from a tuple.Exchange
replaces a single element in a tuple.
All methods have a corresponding *Type
function used within the type checker
to validate the type.