Modify the Reflang language so that the locations 0, 1, and 2 are treated specially as standard

Question:

Modify the Reflang language so that the locations 0, 1, and 2 are treated specially as standard input, standard output, and standard error, respectively. Take the following steps to implement this functionality:
1. Modify the heap abstraction so that it allocates memory starting with location 3.
2. Modify the initial environment so that the names stdin, stdout, and stderr are mapped to reference values loc:0, loc:1, and loc:2, respectively.
3. Modify the semantics of a free expression so that attempts to free the locations 1, 2 and 3 result in a dynamic error with the messages, “Illegal attempt to free stdin,” “Illegal attempt to free stdout,” and “Illegal attempt to free stderr,” respectively.
4. Modify the semantics of a dereference expression so that attempts to dereference locations 1 and 2 result in a dynamic error with the messages “Illegal read from stdout” and “Illegal read from stderr,” respectively. Further, modify the semantics of dereference expression so that attempts to dereference location 0 result in a call to internal read from standard input in your defining language and return the line read from the standard input as a string value. If reading from input causes an input exception, the result should be a dynamic error with the message, “Read from stdout failed.”
5. Modify the semantics of an assign expression so that attempts to assign to location 0 result in a dynamic error with the message, “Illegal write to stdin.” Further, modify the semantics of an assign expression so that attempts to assign to locations 0 and 1 result in printing the value being assigned (RHS) on System.out and System.err, respectively. The value of the assign expression in those cases should be a unit value.
The following interaction log illustrates the properties of the resulting language:image

image

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

Step by Step Answer:

Question Posted: