|
CS 3723/3721 Programming Languages Spring 2005 Recitation 3 Lexical Analysis or Scanning Week 3: Jan 31-Feb 4 Due (on time): 2005-02-07 23:59:59 Due (late): 2005-02-11 23:59:59 |
Recitation 3 must be submitted
following directions at: submissions with deadlines
|
Stated another way, a scanner converts a simple input stream of characters into a simple output stream of tokens.
Because of the third "catch-all" type of token above, your scanner will not need any error messages. It should accept any sequences of tokens at all, including ones that would be insane in any kind of a program. (The software will be catching syntax errors later on.) Here are additional requirements for the scanner:
Notice that single letters will look like identifiers, unless they are the e in a floating point constant, and single digits will look like an integer constants, unless they are part of an identifier. For identifiers, your scanner should return a @ character, which will then not be allowed on input. For integer and floating point constants, your scanner should return a # character, which again will then not be allowed on input.
|
Contents of submission
for Recitation 3: Last Name, First Name; Course Number; Recitation Number (3). a. The Java or C++ source files for your scanner. Everything should be run together into one file, with reasonable separators between components (the separate source files). The code should be reasonably organized and written, with special emphasis on header comments. (Not much emphasis on inline comments.) b. You should give the results of a run using the following simple source file for input. This might be a goal for an initial version of your scanner.
rate = 14; time = 2; distance = rate * time; cost = 6*distance; $ c. You should give the results of a run using the following more complex source file for the input. (If you do this part, you can skip part b above.)
rate = 14.3; /* initial rate is 14.3 */ time0 = 2.; /* initial time is 2.0 */ distance = rate * time0; /* distance is rate times time */ cost2005 =/***/.6e-2*distance/* */+/**/2e2; /* cost for 2005 */ $ /* optional, in case you need an eof sentinel */ Output format: In c above, your output might look like the following. (Note that I generated the output below by hand, so it might have errors in it.)
Token idVal doubleVal Line Number @ rate - 1 = - - 1 # - 14.3 1 ; - - 1 @ time0 - 2 = - - 2 # - 2.0 2 ; - - 2 @ distance - 3 = - - 3 @ rate - 3 * - - 3 @ time0 - 3 ; - - 3 @ cost2005 - 4 = - - 4 # - 0.0060 4 * - - 4 @ distance - 4 + - - 4 # - 200.0 4 ; - - 4
|