Answers are in red (points in parens).
S ---> F {'^' F}
A ---> a (A any non-terminal, a any terminal) A ---> a B (A any non-terminal, a any terminal, B any non-terminal)
As a regular expression, the description would be:
As a regular grammar, the description would be:
ab*c|c
or fully parenthesized:
(((a(b*))c)|c)
A ---> a B
A ---> c
B ---> b B
B ---> c
where A is the start symbol.
private void X() { // 1: start of code to parse the statement Declare variable, say "res" and "label" (Items given under #2 below could be here instead) if (next == '{') { scan(); // 2: start of code to parse next portion Output a label, say "Whilestart:" res = E(); } else error(); // 3: start of code to parse next portion Output a "lw $t1" instr., offset 4 times res from base Output a "beq $t1, $0" instr., to some label, say "WhileEnd" if (next == '?') { scan(); while (next != '}') { S(); // 4: location for code inside loop Nothing here (except MIPS code produced by S()) } else error(); if (next == '}') scan(); else error(); // 5: end of code for statement Output a "j WhileStart" instr. to match label in #2 above Output a label, say "WhileEnd" to match label in #3 above }
int F(int x, char y) { int a[4] = {1, 2, 3, 4}; return a[2]; }what additional information will be placed in the object? In the case above, there must be room for the two parameters and for the array. This function has a return value that also must be taken care of, probably on the stack.
% java ParenLisp 1 + 2 * 3 $ (+ 1 (* 2 3)) % java ParenLisp (1 + (2 * 3)) $ (+ 1 (* 2 3)) % java ParenLisp 1*(2+3)$ (* 1 (+ 2 3)) | % lisp > (+ 1 (* 2 3)) 7 > (* 1 (+ 2 3)) 5 > (quit) % |