Java Reference
In-Depth Information
b. Compute the Action and Goto tables for this grammar.
c. Show the steps in parsing bdc .
d. Is this an LALR(1) grammar?
Exercise 3.20. Show that the following grammar is LR(1) but not LALR(1).
S ::= a B c j b C d j a C db B d
B ::= e
C ::= e
Exercise 3.21. Modify the Parser to parse and return nodes for the double literal and
the float literal.
Exercise 3.22. Modify the Parser to parse and return nodes for the long literal.
Exercise 3.23. Modify the Parser to parse and return nodes for all the additional opera-
tors that are defined in Java but not yet in j--.
Exercise 3.24. Modify the Parser to parse and return nodes for conditional expressions,
for example, (a>b)?a:b .
Exercise 3.25. Modify the Parser to parse and return nodes for the for-statement, in-
cluding both the basic for-statement and the enhanced for-statement.
Exercise 3.26. Modify the Parser to parse and return nodes for the switch-statement.
Exercise 3.27. Modify the Parser to parse and return nodes for the try-catch-finally
statement.
Exercise 3.28. Modify the Parser to parse and return nodes for the throw-statement.
Exercise 3.29. Modify the Parser to deal with a throws-clause in method declarations.
Exercise 3.30. Modify the Parser to deal with methods and constructors having variable
arity, that is, a variable number of arguments.
Exercise 3.31. Modify the Parser to deal with both static blocks and instance blocks in
type declarations.
Exercise 3.32. Although we do not describe the syntax of generics in Appendix C, it is
described in Chapter 18 of the Java Language Specification [Gosling et al., 2005]. Modify
the Parser to parse generic type definitions and generic types.
Exercise 3.33. Modify the j--.jj le in the compiler's code tree for adding the above
(3.22 through 3.31) syntactic constructs to j--.
Exercise 3.34. Say we wish to add a do-until statement to j--. For example,
do{
x=x*x;
}
until(x>1000);
a. Write a grammar rule for defining the context-free syntax for a new do-until statement.
b. Modify the Scanner to deal with any necessary new tokens.
c. Modify the Parser to parse and return nodes for the do-until statement.
 
Search WWH ::




Custom Search