So. My TA has responded with the following, in reference to the read statement:
Code: Select all
(defun interpret-read-statement (read-variable state)
(let ((memory (first state))
(input (second state)
(output (third state))
(list (set-value memory read-variable "this is a phony read value!!!") input output)))
"This is almost correct except value must be extracted from the input list. Then, input list must be adjusted to contain the remaining elements (values)."
and the following BNF grammar for the other two pieces:
if_statement ::=
(if expression then statement_list1 else statement_list2)
For if-statement, you must pass expression, statement_list1, statement_list2 and the state, then evaluate in the interpret-if-statement.
while_statement ::=
(while expression do statement_list)
For while-statement, you must pass expression, statement_list and the state.
- Show quoted text -
So. For starters. would the following be correct for the read statement, making the following assumptions. The command put to the interpreter is:
((interpret-program '(read x) (write x) '(21))
Which would make the "value" portion of "state" the third item in the list. Correct?
Then, in the return statement, we need to remove "value" from state. so it would be a list containing everything except the third value:
Code: Select all
(defun interpret-read-statement (read-variable state)
(let ((memory (first state))
(input (second state)
(output (third state))
(value (third state))
(list (set-value memory read-variable (cdddr(state))) input output)))
How does that look?