type complex = record re, im: real end; person = record name: alfa; age: integer; location: complex; weight: real; salary: real end; var people = array [ 7..14, (austin, dallas, houston)] of person;
Answer: complex contains 2 reals, for a total of 16 bytes.
The person record has the following layout:
Field: | Offset: | Size: | Comment: |
name | 0 | 8 | |
age | 8 | 4 | |
12 | 4 | padding | |
location | 16 | 16 | records are 16-aligned |
salary | 32 | 8 | reals are 8-aligned |
weight | 40 | 8 | |
Total | 48 |
The array size should be calculated back-to-front to provide numbers that are used in the next step. (austin, dallas, houston) is 3 items, 3*48 = 144 bytes. Using the formula (high - low + 1), the array is (14 - 7 + 1) * 144 = 8*144 = 1152 bytes.
people[10,dallas].location.imShow how it was derived and give the aref form.
Answer: We calculate the offset by adding the components, left-to-right:
Item: | Value: | Multiplier: | Subtotal: |
[10] | (10 - 7) | 144 | 432 |
dallas | (1 - 0) | 48 | 48 |
location | 16 | 1 | 16 |
im | 8 | 1 | 8 |
Total | 504 |
A - (B / C - D) / E + FShow the contents of the stacks at each step; produce a tree as output.
Answer: This can be done using either a diagram or parenthesized notation for the tree structure.
Item: | Operators: | Operands: | Note: |
A | A | Shift A | |
- | - | A | Shift - |
( | - ( | A | Shift ( |
B | - ( | A B | Shift B |
/ | - ( / | A B | Shift / |
C | - ( / | A B C | Shift C |
- | - ( | A (/ B C) | Reduce: / > - |
- | - ( - | A (/ B C) | Shift - |
D | - ( - | A (/ B C) D | Shift D |
) | - ( | A (- (/ B C) D) | Reduce |
) | - | A (- (/ B C) D) | Discard () |
/ | - / | A (- (/ B C) D) | Shift / |
E | - / | A (- (/ B C) D) E | Shift E |
+ | - | A (/ (- (/ B C) D) E) | Reduce: / > + |
+ | (- A (/ (- (/ B C) D) E)) | Reduce: - = + | |
+ | + | (- A (/ (- (/ B C) D) E)) | Shift + |
F | + | (- A (/ (- (/ B C) D) E)) F | Shift F |
end | (+ (- A (/ (- (/ B C) D) E)) F) | Reduce |
Answer: Adv: Fast, O(1). Dis: Must find a good hash function, must expand table when it gets too full (> 70%).
Answer: b+ can absorb b*. b+ = b*b. (a | b)* can absorb b*. What is left is (a | b)*b.
Answer: A -> xB, A -> x where A and B are nonterminals, x is a terminal string.
S --> a S S --> S b S --> b
Answer: It has a single nonterminal on the left of each production (thus is Context Free) but does not fit the Regular production pattern, so it is Context Free.
Answer: a*b+ is the language denoted. Since a*b+ is a regular expression, the language must be Regular.
Answer:
S --> a S S --> T T --> b T T --> bThis is a Regular grammar that denotes the same language.