Question: Your lexical analyzer should be implemented in a class called Lexer.java class Lexer.java should have a static method called Tokenize(String fileName) . The method takes

Your lexical analyzer should be implemented in a class called Lexer.java class Lexer.java should have a static method called Tokenize(String fileName). The method takes the source code file name as input and generates (prints on the screen) the equivalent sequence of tokens. Each token is on a new line. Your code must produce the correct output for the testcase.txt as shown in testcase_tokenized.txt.

Your lexical analyzer should be implemented in a class called Lexer.java class

textcase.txt procedure calculateTax(int bracket)

for(int i = 0; i

if(bracket >= 1000) break; }

return bracket;

end calculateTax

int 9user = 5;

textcase_tokenized.txt PROC IDENT LP INT IDENT RP FOR LP INT IDENT ASSIGN INT_CONST SEMI IDENT LT IDENT SEMI IDENT ASSIGN IDENT INC RP LB IDENT ASSIGN IDENT MUL_OP LP IDENT DIV_OP INT_CONST RP SEMI IF LP IDENT GE INT_CONST RP BREAK SEMI RB RETURN IDENT SEMI END IDENT INT SYNTAX ERROR: INVALID IDENTIFIER NAME

Introduction: - In the first phase of compilation, the compiler analyzes the structure of the input source code in three steps: lexical analysis, parsing, and semantic analysis. - The lexical analyzer reads individual characters of the input source code and groups them into the words of the language: identifiers, constants, and symbols. - An individual word (a lexeme) is then represented as a token object and returned to the parser. Assignment Description: In this assignment, you will be creating a lexical analyzer for a simple programming language. The language has the following reserved symbols: - Identifiers (procedures names, variable names) are alphanumeric; however, they must begin with an alphabetical character. The token for identifiers is IDENT - The token for integers is INT_CONST

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!