1 | # Rick van der Zwet
|
---|
2 | # StudentID: 0433373
|
---|
3 | # $Id: lecture2.txt 248 2007-10-04 19:37:40Z rick $
|
---|
4 |
|
---|
5 | All quotes are based on the 7th edition of Concepts of programming
|
---|
6 | languages from Robert W. Sebesta, cause the 8th edition has not come in
|
---|
7 | yet
|
---|
8 |
|
---|
9 | *** Chapter 3 Review Questions ***
|
---|
10 |
|
---|
11 | 2)
|
---|
12 | Q: Who are language descriptions for?
|
---|
13 | A: "One of the problems ... about a language" pg. 124 sect. 3.1
|
---|
14 |
|
---|
15 | 3)
|
---|
16 | Q: Describe the operation of a general language generator
|
---|
17 | A: "A language generator ... it is pushed" pg. 126 sect. 3.2.2
|
---|
18 |
|
---|
19 | 6)
|
---|
20 | Q: Define a left recursive grammar rule.
|
---|
21 | A: "In this derivation ... leftmost drivations" pg 130
|
---|
22 | Example: <stmt> => <stmt> , <id>
|
---|
23 | | <id>
|
---|
24 | <id> => A | B | C
|
---|
25 |
|
---|
26 | 8)
|
---|
27 | Q: Distinguish between static and dynamic semantics.
|
---|
28 | A: "Static semantics is .. at compile time" pg. 142 sec. 3.4.1
|
---|
29 |
|
---|
30 | 9)
|
---|
31 | Q: What purpose do predicates service in an attribute grammer?
|
---|
32 | A: "Predicates functions, which .. with grammar rules." pg. 142. sec. 3.4.2
|
---|
33 |
|
---|
34 | 10)
|
---|
35 | Q: What is the difference between a synthensized and an inherited
|
---|
36 | attribute?
|
---|
37 | A: "Synthesized attributes are ... across a tree" pg. 143 sect. 3.4.3
|
---|
38 |
|
---|
39 | 13)
|
---|
40 | Q: What is the problem with using a software pure interpreter for
|
---|
41 | operation semantics?
|
---|
42 | A: "First, the copmlexities ... configured computer." pg. 149
|
---|
43 |
|
---|
44 | *** Chapter 3 Problem Set ***
|
---|
45 | 19) Compute the weakest precondition for each of the following
|
---|
46 | assignment statements and postconditions:
|
---|
47 |
|
---|
48 | 19a)
|
---|
49 | Q: a = 2 * (b - 1) - 1 {a > 0}
|
---|
50 | A: 2 * (b - 1) - 1 > 0
|
---|
51 | A b > 1.5
|
---|
52 |
|
---|
53 | 19b)
|
---|
54 | Q: b = (c + 10) / 3 {b > 6}
|
---|
55 | A: (c + 10) / 3 > 6
|
---|
56 | c > 8
|
---|
57 |
|
---|
58 | 19c)
|
---|
59 | Q: a = a + 2 * b - 1 {a > 1}
|
---|
60 | A: a + 2 * b - 1 > 1
|
---|
61 | b > 0.5a + 1
|
---|
62 |
|
---|
63 | 19d)
|
---|
64 | Q: x = 2 * y + x - 1 {x > 11}
|
---|
65 | A: 2 * y + x - 1 > 11
|
---|
66 | y > 6 - 0.5x
|
---|
67 |
|
---|
68 | 20) Compute the weakest precondition for each of the following
|
---|
69 | assignment statements and postconditions:
|
---|
70 |
|
---|
71 | 20a)
|
---|
72 | Q: a = 2 * b + 1;
|
---|
73 | b = a - 3
|
---|
74 | {b < 0}
|
---|
75 | A: a - 3 < 0
|
---|
76 | {a < 3}
|
---|
77 | 2 * b + 1 < 3
|
---|
78 | {b < 1}
|
---|
79 |
|
---|
80 | 20b)
|
---|
81 | Q: a = 3 * (2 * b + a);
|
---|
82 | b = 3 * a - 1
|
---|
83 | {b > 5}
|
---|
84 | A: 3 * a - 1 > 5
|
---|
85 | {a > 2}
|
---|
86 | 6 * 3b + 3a > 2
|
---|
87 | 18b + 3a > 2
|
---|
88 | 18b > 2 - 3a
|
---|