- Print version, with cover page (pdf)
- Due Date: Monday, September 25
Pick a pair of two programming languages that you know, and come up with an example of each of the following in your two languages. As always, you can work together, but everyone must turn in unique examples.
A homograph is a code fragment that is the same syntactically between the two languages, but has different semantics in each.
A synonym is a code fragment that is the same semantically between the two languages, but has different syntax.
C++ and Java support a few different kinds of numerical constants, or
“literals”. The most basic are regular ints that you know and love like
32. There are also
floating-point numbers like
For this problem, consider an
INT token to be any
sequence of 1 or more digits
[0-9], and a
FLOAT token to be any sequence of 1 or more digits which
contains exactly one decimal point
Draw the DFA for a scanner that accepts
INT tokens. Be sure to label each accepting state with the
type of token, and put characters or character ranges on each
Modify your scanner DFA from the previous problem so that it also accepts an additional type of token, a
HEXconstant such as
For this problem, a
HEXtoken contains the symbols
0xfollowed by zero or more digits or letters in the range
- Note that the previous definition allows for the string
0xby itself to be considered a
HEXtoken. What problem would there be if we disallowed this, so that
0xis not a valid token but, for example,
Write a grammar that is ambiguous, and then show that it is ambiguous by coming up with a series of tokens that could be parsed in two different ways according to your grammar.