|
CS 3723/3721 Programming Languages Fall 2004 Recitation 3 Lexical Analysis or Scanners Week 3: Sep 8-10 Due (on time): 2004-09-13 23:59:59 Due (late): 2004-09-17 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:
|
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 */ time0 = 2.; /* initial time */ distance = rate * time0; /* distance is rate times time */ cost2004 =/***/.6e-2*distance/* */+/**/2e2; /* cost for 2004 */ $ /* optional, in case you need an eof sentinel */ Output format: In b and c above, your output should be each scanned token, in case of an identifier the symbol table location, and in case of a constant, the value as a double, followed finally by the line number. At the end you must also print the symbol table. Thus the output for c above might look like the following. (Below, I put in extra spaces for clarity, but you don't need them. Note that I generated the output below by hand, so it might have errors in it.)
Token Value Line Number @ 0 1 = - 1 # 14.3 1 ; - 1 @ 1 2 = - 2 # 2.0 2 ; - 2 @ 2 3 = - 3 @ 0 3 * - 3 @ 1 3 ; - 3 @ 3 4 = - 4 # 0.0060 4 * - 4 @ 2 4 + - 4 # 200.0 4 ; - 4 Symbol Table 0 rate 1 time0 2 distance 3 cost2004
|