Java Reference
In-Depth Information
2.11 Exercises
Exercise 2.1. Consult Chapter 3 (Lexical Structure) of The Java Language Specification
[Gosling et al., 2005]. There you will nd a complete specication of Java's lexical syntax.
a. Make a list of all the keywords that are in Java but not in j--.
b. Make a list of the escape sequences that are in Java but are not in j--.
c. How do Java identifiers differ from j-- identifiers?
d. How do Java integer literals differ from j-- integer literals?
Exercise 2.2. Draw the state transition diagram that recognizes Java multi-line comments,
beginning with a /* and ending with */ .
Exercise 2.3. Draw the state transition diagram for recognizing all Java integer literals,
including octals and hexadecimals.
Exercise 2.4. Write a regular expression that describes the language of all Java integer
literals.
Exercise 2.5. Draw the state transition diagram that recognizes all Java numerical literals
(both integers and floating point).
Exercise 2.6. Write a regular expression that describes all Java numeric literals (both
integers and floating point).
Exercise 2.7. For each of the following regular expressions, use Thompson's construction
to derive a non-deterministic finite automaton (NFA) recognizing the same language.
a. aaa
b. (ab)ab
c. abcd
d. (ajbc)a
e. (ajb)
f. ajb
g. (ajb)
h. ((aa)(ab)(ba)(bb))
Exercise 2.8. For each of the NFA's in the previous exercise, use powerset construction
for deriving an equivalent deterministic finite automaton (DFA).
Exercise 2.9. For each of the DFA's in the previous exercise, use the partitioning method
to derive an equivalent minimal DFA.
The following exercises ask you to modify the hand-crafted scanner in the j-- compiler
for recognizing new categories of tokens. For each of these, write a suitable set of tests, then
add the necessary code, and run the tests.
 
Search WWH ::




Custom Search