Extend the Varlang programming language from the previous question to implement a substitution-based variation of the let

Question:

Extend the Varlang programming language from the previous question to implement a substitution-based variation of the let expression (say a lets expression). Recall that a substitution-based semantics works as follows. The value of (lets ((x 3)(y 4)) (+ x y)) is the value of a new expression created from the original let body (+ x y) by replacing x with 3 and y with 4. According to the substitution-based semantics, the value of the let expression is the value of (+ 3 4), which is 7.

The grammar of this new language feature should be exactly the same as the grammar of the let expression in the Varlang language, except for the keyword lets.

Implement substitution as a subst method for each AST node such that given a list of variable names and a list of values, the subst method returns a copy of current AST node with each free variable name substituted for a corresponding value.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Question Posted: