blob: a669ea67d602e866694c342c2d198054659b0813 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# COMP-200: Intro to Computer Systems
## Assignment 4
### mo khan - 3431709
Choose ONE exercise each from Chapters 10, 11, and 12.
There are no chapter end exercises for Chapter 9.
Chapter 10:
> 9. In Python, indentation is used to indicate the extent of a block of code. What is the output of the following Python code?
```python
!include assignments/4/main.py
```
```bash
$ python assignments/4/main.py
second is bigger
first is bigger
```
Chapter 11:
Figure 11.9
1. Identify the tokens in each of the following statements. (You do not need to classify them; just identify them.)
a. `if (a == b1) a = x + y;`
| token | type |
| ----- | ---- |
| if | if condition |
| ( | left paren |
| a | symbol |
| == | comparison operator |
| b1 | symbol |
| a | symbol |
| = | assignment operator |
| x | symbol |
| + | addition operator |
| y | symbol |
| ; | statement terminator |
b. `delta = epsilon + 1.23 - sqrt(zz);`
| token | type |
| ----- | ---- |
| delta | symbol |
| = | assignment operator |
| epsilon | symbol |
| + | addition operator |
| 1.23 | floating point number |
| - | subtraction operator |
| sqrt | symbol |
| ( | left paren |
| zz | symbol |
| ) | right paren |
| ; | statement terminator |
c. `print(Q);`
| token | type |
| ----- | ---- |
| print | symbol |
| ( | left paren |
| Q | symbol |
| ) | right paren |
| ; | statement terminator |
Chapter 12:
> 5. Given the Turing machine instruction `(1,1,0,2,L)` and the configuration `...b 1 0 b...` draw the next configuration.
* `(1,1,0,2,L)` - Move left once and halt the machine
```plaintext
--------|*|----------
|.|.|.|b|1|0|b|.|.|.|
--------|*|----------
^
|- 1
```
```plaintext
------|*|------------
|.|.|.|b|0|0|b|.|.|.|
------|*|------------
^
|- 2
```
|