









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










Adding user defined functions to the minilanguage^ ¾^ parameter passing^ ¾^ local variables (local environment)^ ¾^ function application^ ^ Execute procedure body in local environment with formalparameters bound to actual argument values^ ¾^ return value^ ¾^ recursion Exercise 2: Modify the extended Mini Languageand interpreter to use an explicit return statement
Discuss assignment 2^ ¾^ Add lists to the mini language^ ¾^ Values are now lists or ints (modify Environment)^ ¾^ Support list constants and built-in list processingfunctions^ ^ cons( e, L ) - appends element e to the front of list^ ^ car( L ) - returns the first element in the list^ ^ cdr( L ) - returns the rest of the list (minus the first element)^ ^ nullp( L ) - returns 1 if L is null, 0 otherwise^ ^ intp( e ) - returns 1 if e is an integer, 0 otherwise^ ^ listp( e ) - returns 1 if e is a list, 0 otherwise to allowconstruction and access to lists.
Let an Environment be a map from indentifiers tovalues = integers
∪^ undefined Mini language programs can be thought of as amap from an initial Environment to a finalEnvironment (assuming it terminates) The initial environment maps all identifiers to anundefined Each statement is defined in terms of what it doesto the current environment (another mapping)
Example Mini Language Program 1. n := 0 -
Example Mini Language Procedure define add proc(n) i := n; s := 0; while i do s := s + i; i := i-1 od; return := s end; n := 5; s := add(n) What is the final environment?
Example Recursive Mini Language
Procedure