This project involves the design and implementation of an interpreter for the Number-Expression Programming Language (NUMEX). NUMEX programs are written in Racket using constructors defined by the structs. The language supports various expressions, including arithmetic operations, logical operations, conditional expressions, functions, and more. The project assumes that NUMEX programs are syntactically correct and free of type errors.
The project is explained in detail in the docs/instructions.pdf file, in English.
- Variables, numbers, booleans
- Arithmetic (
+
,-
,*
,/
), logical (andalso
,orelse
), and comparison (iseq
) operations - Conditionals (
cnd
,ifnzero
,ifleq
) - Functions (
lam
), function application (apply
) - Let bindings (
with
) - Pairs (
apair
) and list operations (1st
,2nd
) - Recursion (
letrec
) - Records (
key
,record
,value
)
-
Warm-Up: Implement two Racket functions:
racketlist->numexlist
: Converts a Racket list to a NUMEX list.numexlist->racketlist
: Converts a NUMEX list to a Racket list.
-
Implementing NUMEX: Implementing NUMEX consists of the following tasks.
- Implement NUMEX interpreter (
eval-exp
) as a Racket function: takes a NUMEX expression and returns the NUMEX value it evaluates to under the empty environment or calls Racket's error if evaluation encounters a run-time NUMEX type error or unbound NUMEX variables. - Implement simple NUMEX type system (
infer-exp
) - Write NUMEX macros for NUMEX extensions: Example Racket functions producing NUMEX expressions that could then
be put inside larger NUMEX expressions. (
ifmunit
,with*
,ifneq
) - Example usage of NUMEX functions by writing NUMEX functions for list filtering (
numex-filter
) and comparisonnumex-all-gt
. - Experiment with type system limitations:
type-error-but-evaluates-ok
: An example expression that the type system infers as a type error but the interpreter evaluates it fine.type-ok-but-evaluates-error
: An example expression that the type system infers it fine but the interpreter evaluates it as an error.
- Optimize interpreter with free variable analysis (
eval-exp-c
): Building closures with smaller environments by holding only variables that are free variables in the function part of the closure. This is achieved via a utility functioncompute-free-vars
- Implement NUMEX interpreter (
- Course: Programming Languages
- University: Amirkabir University of Technology
- Semester: Fall 2022
Let me know if you have any questions.