You are welcome to work in small groups on written homework assignments. However, if you do so, I suggest first trying to solve all the problems individually, then meeting as a group to come up with a final solution together (rather than having each member solve a subset of them individually); it is good to test your understanding of the material by trying to solve every homework problem on your own first. If you work in a group, please submit a single solution with all of your names on it, so that it is clear with whom you collaborated and so that I do not have to grade several identical solutions.
You should submit a hardcopy of your written homework assignments.
Either email me your solution before the due date or hand it in to Rich before the due date (either in person or slide it under his office door).
B --> B || T B --> T T --> T && F T --> F F --> true F --> falseUsing your parse table, show the shift-reduce parse steps (like I do in class) for the parse of the string: true || false
// program 1:
int main () {
write 9;
writeln;
}
// program 2:
int main () {
write (9 + 2 * 4);
writeln;
}
// program 3:
// for this one, do not try to optimize the code you write
// by removing some loads and stores, instead implement MIPS code
// that a naive compiler would generate: a store instruction for
// x = 8, followed by a load instruction to get x for 3 + x, ...
int x;
int main () {
x = 8;
x = 3 + x;
write x;
writeln;
}
hand in this assignment by emailing me your three MIPS assembly files as
attachments.
Expr --> Expr + Expr
| Expr * Expr
| Expr POW NUM
| (Expr)
| NUM
where POW is the exponentiation operator (e.g. 2 POW 4 is 16), is right
associative, and has higher precedence than *
Do the following:
(a | ab)*This problem is designed to give you some practice with the algorithms we discussed in class. In your solution, you should show all the steps of applying these algorithms (don't just come up with a DFA for this regular expression, which I'm sure you can do without applying the algorithms).
As an extra challenge, try problem 2.2.5.
If you do not know binary number representation, here is a brief description
(X^K is notation for X raised to the Kth power):
binary numbers are base 2 numbers consisting of strings of 0's and 1's
decimal numbers are base 10 numbers consisting of strings of {0,1,...,9}
base 3 numbers consist of strings of {0, 1, 2}
base 4 numbers consist of string os {0, 1, 2, 3}
and so on
for any base number:
the lowest order digit counts the number of base^0 occurrences in the value
(either 0 occurrences, or 1 occurrence, or ... , or base-1 occurrences)
the 2nd lowest order digit counts the number of base^1 occurrences in the value
the 3rd lowest order digit counts the number of base^2 occurrences in the value
and so on
For example:
the number 101 in decimal has a value of 1*10^2 + 0*10^1 + 1*10^0 = 101
the number 101 in binary has a value of 1*2^2 + 0*2^1 + 1*2^0 = 5
the number 101 in base3 has a value of 1*3^2 + 0*3^1 + 1*3^0 = 10
To represent the decimal value 23 in:
base 10: 2*10^1 + 3*10^0 is 23
base 4: 1*4^2 + 1*4^1 + 3*4^0 is 113
base 2: 1*2^4 + 0*2^3 + 1*2^2 + 1*2^1 + 1*2^0 is 10111
For this problem, the two terminals in the grammar are 11 and 1001, which
are the decimal values 3 and 9.
Copy the simple compiler code (based on the infix to postfix compiler from Chapt. 2)
from ~newhall/public/cs75/simplecompiler/ to one of your
subdirectories. Read the README file, then try compiling and running it with
different infix expression input. By reading through chapt. 2 of the book
and by reading through the simple compiler's source code you will get an idea
of how you will organize and implement parts of your C compiler.
In addition, the main function has some commented-out memory access errors. You may want to try uncommenting these errors, re-making, and then running with valgrind to get some idea of how valgrind works. I'll be giving a gdb and valgrind demo next week.