E ---> E '+' T | T
T ---> T '*' F | F
F ---> '(' E ')' | 'a' | 'b' | 'c' |
E
|
T
+----+---------------------+
| | |
| | F
| | +----------------+-----------+
T | | | |
| | | E |
| | | | |
| | | +-------+------+ |
| | | | | | |
F | | E | T |
| | | | | | |
| | | T | F |
| | | | | | |
| | | F | | |
| | | | | | |
a * ( b + c )
public class Floats {
public static void main (String[] args) {
System.out.println("1e+1: " + 1e+1);
System.out.println(".1: " + .1);
System.out.println("0e0: " + 0e0);
System.out.println("1.e47: " + 1.e47);
}
}
Output:
1e+1: 10.0
.1: 0.1
0e0: 0.0
1.e47: 1.0E47
letter | digit
__
/ \ 0 = start state
| | 2 = terminal state
letter \ / other
----> 0 --------------> 1 ---------- 2
// error handling not required
private void W() {
if (next == '{') scan(); // possibly already checked for '{'
else error();
E();
if (next == '?') scan();
else error();
while (next != '}') {
S();
}
if (next == '}') scan();
else error(7);
}
First a label -- WhileStart0: (with integer tacked onto the end, not necessarily 0) Then MIPS code generated by calling E Final part ends up with an address returned by E where the value of E will be held at run time, call this value returned "addr" Then the instruction -- lw $t1, addr*4($s1) # addr*4 is a constant Then the instruction -- beq $t1, $zero, WhileEnd0 (same digit at end) Then code generated by the calls to S, however many there are Then the instruction -- j WhileStart0 (same digit at end) Then the label -- WhileEnd0: (same digit at end) Note:of course you don't have to use the names "WhileStart" etc. and many other variations from the above are possible.
P ----> Q '#'
Q ----> '(' R
R ----> ')' | Q R