Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Joe Celkos Data And Databases Concepts In Practice

Authors: Joe Celko

1st Edition

1558604324, 978-1558604322

More Books

Students also viewed these Databases questions

Question

=+ Are some laws more important than others? If so, which ones?

Answered: 1 week ago

Question

=+j Describe how EU directives impact IHRM.

Answered: 1 week ago