Question: -Write a lexical analyzer in JAVA OR C as a table-driven problem solver to construct tokens using the Scanner -your code must print out a
-Write a lexical analyzer in JAVA OR C as a table-driven problem solver to construct tokens using the Scanner
-your code must print out a token table like the one listed below
Token Table
| Token | Classification |
| CLASS | $CLASS |
| LargestCommonDenominator |
|
| { | $LB |
| M |
|
| = | |
| 7 | |
| , | |
| N |
|
| = | |
| 85 | |
| ; | |
| VAR | <$var> |
| | |
|
|
|
| } | $RB |
| CONST | $CONST |
| PROCEDURE | $PROCEDURE |
|
|
|
| WHILE | $WHILE |
| DO | $DO |
| < | |
| <= | |
| > | |
| >= | |
| == | |
| != | |
| IF | IF |
| THEN | $THEN |
| ELSE | $ELSE |
| / | |
| * | |
| + | |
| - | |
| CALL | $CALL |
| ( | $LP |
| ) | $RB |
| /* | $LComment |
| */ | $RComment |
- Each time the scanner is called, it should return the next token and its class.
- your program should create a symbol table like the one below
Programs will be summitted to the scanner via text file
CLASS Pgm1 {
CONST M = 13, N = 56;
VAR X, Y, Z;-
Y = 97;
X = M * N + 18 y;
}
Symbol Table
| Token | Class | Value | Address | Segment |
| Pgm1 | |
| 0 | CS |
| M | $CONST | 13 | 0 | DS |
| N | $CONST | 56 | 2 | DS |
| X |
|
| 4 | DS |
| Y |
|
| 6 | DS |
| Z |
|
| 8 | DS |
| 97 | $NumLit | 97 | 10 | DS |
| 18 | $NumLit | 18 | 12 | DS |
Use of java functions such as the StringTokenizer in Java to create tokens is NOT ALLOWED
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
