Java Reference
In-Depth Information
8. When a compiler is first designed and implemented, it is wise to con-
centrate on correctness and simplicity of design. After the compiler is
fully implemented and tested, you may need to increase compilation
speed. How would you determine whether the scanner component of a
compiler is a significant performance bottleneck? If it is, what might you
do to improve performance (without a
ff
ecting compiler correctness)?
9. Most compilers can produce a source listing of the program being com-
piled. This listing is usually just a copy of the source file, perhaps
embellished with line numbers and page breaks. Assume you are to
produce a prettyprinted listing.
(a) How would you modify a Lex scanner specification to produce a
prettyprinted listing?
(b) How are compiler diagnostics and line numbering complicated
when a prettyprinted listing is produced?
10. For most modern programming languages, scanners require little con-
text information. That is, a token can be recognized by examining its text
and perhaps one or two lookahead characters. In Ada, however, addi-
tional context is required to distinguish between a single tic (comprising
an attribute operator, as in data'size) and a tic-character-tic sequence
(comprising a quoted character, as in 'x'). Assume that a Boolean flag
can parse char is set by the parser when a quoted character can be
parsed. If the next input character is a tic, can parse char can be used
to control how the tic is scanned. Explain how the can parse char flag
can be cleanly integrated into a Lex-created scanner. The changes you
suggest should not unnecessarily complicate or slow the scanning of
ordinary tokens.
11. Unlike C, C
, and Java, Fortran generally ignores blanks and therefore
may need extensive lookahead to determine how to scan an input line.
A typical example of this is DO10I=1,10,whichproducesseven
tokens, in contrast with DO10I=1. 10, which produces three to-
kens.
++
(a) Howwould you design a scanner to handle the extended lookahead
that Fortran requires?
(b) Lex contains a mechanism for doing lookahead of this sort. How
would you match the identifier (DO10I)inthisexample?
 
Search WWH ::




Custom Search