Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
Objectives.
1. Support multiline comments.
-
Supportadditional tokens (reserved words, operators, and separators).
-
Support long and double
In this project, you will only be updating the hand-crafted scanner, which means that the only program files you will be modifying under $j/j–/src/jminusminus are TokenInfo.java and Scanner.java.
Run the following command inside the $j directory to compile the j– compiler with your changes.
$ ant clean com pile jar
Run the following command to compile (just scan for now) a j– program P.java using the j– compiler.
$ sh $j /j - -/ bin /j - - -t P . java
which only scans P.java and prints the tokens in the program along with the line number where each token appears.
Problem 1. (Multiline Comment ) Add support for multiline comment, where all the text from the ASCII characters /* to the ASCII characters */ is ignored.
$j /j - -/ bin /j - - -t tests / M ultiL ineC om m ent . java
5 : public = public
5 : class = class
5 : < IDENTIFIER > = M ultiL ineC om m ent 5 : { = {
9 : public = public
9 : static = static
9 : void = void
9 : < IDENTIFIER > = main
9 : ( = (
9 : < IDENTIFIER > = S tring
9 : [ = [
9 : ] = ]
9 : < IDENTIFIER > = args
9 : ) = )
9 : { = {
13 : } = }
14 : } = }
15 : < EOF > = < EOF >
Problem 2. (Reserved Words) Add support for the following reserved words.
break
|
case
|
catch
|
continue
|
default
|
do
|
double
|
final
|
finally
|
for
|
im plem ents
|
interface
|
long
|
sw itch
|
throw
|
throw s
|
try
|
|
$j /j - -/ bin /j - - -t tests / R eserved W ords . java
1 : break = break
1 : case = case
1: catch =catch
2: continue =continue
2 : default = default
2: do =do
3: double =double
3 : final = final
3: finally =finally
4: for =for
4 : im plem ents = im plem ents
4 : interface = interface