Название: Concepts and Semantics of Programming Languages 1
Автор: Therese Hardin
Издательство: John Wiley & Sons Limited
Жанр: Программы
isbn: 9781119824091
isbn:
6) Consider the sequence
Determine the states etat3 = (Env3
Exercise 2.2
The two constructs x + + and + + x:
are added to the language Exp1. In these two new constructs, the identifier x must be a mutable variable. Intuitively, we see that the evaluation of the expression x + + produces the value stored in the location denoted by x and increments the value in the memory by 1. The expression + + x is evaluated differently: the value stored at the location denoted by x is incremented by 1, and this new value is the result of the evaluation.
1) Define an evaluation function:for expressions in the language Exp1, extended so that expresses the fact that evaluation of the expression e in the state (Env, Mem) transforms this state into a state (Env’, Mem’) and produces the value v.
2) Let Env = [(x, rx)] and Mem = [(rx, 6)]. Compute:
3) Show that, for any state (Env, Mem):Now, we extend the language Lang1 by considering the expressions of the extended Def 1 language and adding the construction x+ := e. In informal terms, the execution of this instruction in a state (Env, Mem) consists of first finding the value vx stored at the reference v in Mem, then evaluating the expression e in this state to obtain its value ve and a new state (Env’, Mem’), and finally, assigning to v the result of the addition of ve and vx. If at least one of the two values ve and vx is not an integer, the execution fails.
4) Redefine the relation →Lang1 for the extended Lang1 language.
5) Let Env0 = [(x, rx)] and Mem0 = [(rx, 2)]. Determine the state etat1 such that
6) Do the assignments x := x + +, x := + + x and x+ := 1 produce the same states when executed in the same state?
Конец ознакомительного фрагмента.
Текст предоставлен ООО «ЛитРес».
Прочитайте эту книгу целиком, купив полную легальную версию на ЛитРес.
Безопасно оплатить книгу можно банковской картой Visa, MasterCard, Maestro, со счета мобильного телефона, с платежного терминала, в салоне МТС или Связной, через PayPal, WebMoney, Яндекс.Деньги, QIWI Кошелек, бонусными картами или другим удобным Вам способом.