- Support multiline comments.
- Support additional 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 compile 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/MultiLineComment.java5 : public = public5 : class = class5 : <IDENTIFIER> = MultiLineComment5 : { = {9 : public = public9 : static = static9 : void = void9 : <IDENTIFIER> = main9 : ( = (9 : <IDENTIFIER> = String9 : [ = [9 : ] = ]9 : <IDENTIFIER> = args9 : ) = )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 | implements | interface | |
| long | switch | throw | |
| throws | try | ||
| $ $j/j/bin/j -t tests/ReservedWords.java1 : break = break 1 : case = case1 : catch = catch2 : continue = continue2 : default = default2 : do = do3 : double = double3 : final = final3 : finally = finally4 : for = for4 : implements = implements4 : interface = interface | |||
| 5 | : long = long | ||
| 5 | : switch = switch | ||
| 5 | : throw = throw | ||
| 6 | : throws = throws | ||
| 6 | : try = try | ||
| 7 | : <EOF> = <EOF> | ||
Problem 3. (Operators) Add support for the following operators. Note that some of the arithmetic, shift, and bitwise operators were added to j in Project 1.
| ? | ~ | != | / | /= |
| -= | *= | % | %= | |
| >> | >>= | >>> | >>>= | >= |
| << | <<= | < | ^ | ^= |
| | | |= | || | & | &= |
| $ $j/j/bin/j -t tests/Operators.java1 : ? = ?1 : ~ = ~1 : != = != 1 : / = /1 : /= = /= 2 : -= = -= 2 : = 2 : *= = *= 2 : % = %2 : %= = %= 3 : >> = >>3 : >>= = >>= 3 : >>> = >>>3 : >>>= = >>>=3 : >= = >= 4 : << = <<4 : <<= = <<=4 : < = < 4 : ^ = ^4 : ^= = ^= 5 : | = |5 : |= = |=5 : || = || 5 : & = &5 : &= = &=6 : <EOF> = <EOF> | ||||
Problem 4. (Separators) Add support for the separator : (colon).
| $ $j/j/bin/j -t tests/Separators.java1 : ; = ; 2 : : = : 3 : , = , 4 : . = .5 : [ = [5 : { = {5 : ( = (5 : ) = )5 : } = }5 : ] = ]6 : <EOF> = <EOF> |
Problem 5. (Literals) Add support for (just decimal for now) long and double literals. Your are not allowed to use regular expressions to scan literals.
| <int_literal> = 0 | (1-9) {0-9} // decimal<long_literal> = <int_literal> (l | L)<digits> = (0-9) {0-9}<exponent> = (e | E) [(+ | -)] <digits><suffix> = d | D<double_literal> = <digits> . [<digits>] [<exponent>] [<suffix>]| . <digits> [<exponent>] [<suffix>]| <digits> <exponent> [<suffix>]| <digits> [<exponent>] <suffix> |
| $ $j/j/bin/j -t tests/Literals.java1 : <INT_LITERAL> = 01 : <INT_LITERAL> = 21 : <INT_LITERAL> = 3722 : <LONG_LITERAL> = 1996l 2 : <LONG_LITERAL> = 777L2 : <DOUBLE_LITERAL> = .3D3 : <DOUBLE_LITERAL> = 3.143 : <DOUBLE_LITERAL> = 6.022137e+233 : <DOUBLE_LITERAL> = 1e-9d4 : <EOF> = <EOF> |

![[Solved] CS451651 Project2- Scanning](https://assignmentchef.com/wp-content/uploads/2022/08/downloadzip.jpg)

![[Solved] CS451651 Project5- Type Checking and Code Generation](https://assignmentchef.com/wp-content/uploads/2022/08/downloadzip-1200x1200.jpg)
Reviews
There are no reviews yet.