subject

Lexical Analyzer Implementation

Use Java to write a simple Lexical Analyzer.

Input: a source code file, (.txt file). Ask user to input the file name.

Output: printing all recognized tokens

The source code accepted tokens include

Keywords: int double String (case sensitive)

operators: = ( ) + - * / , ;

identifier: letter(letter|digit)*

int constant

double constant

string constant: string constant is enclosed in a pair of "", such as "abc"

anything not recognized is detected as errors

If the input file has the following content:

int a, b=10;

a =bc*10-&(3.2+"abc";

The output should be

Line1:1 keyword: int

Line1: 5 identifier: a

Line1:6 operator: ,

Line1: 7 identifier: b

Line1: 8 operator: =

Line1: 9 int constant: 10

Line1: 11 operator: ;

Line2: 1 identifier: a

Line2: 3 operator: =

Line2: 4 identifier: bc

Line2: 6 operator: *

Line2: 7 int constant: 10

Line2: 9 operator: -

Line2: 10 error: & not recognized

Line2: 11 operator: (

Line2: 12 double constant: 3.2

Line2: 15 operator: +

Line2: 16 string constant: "abc"

Line2: 21 operator: ;

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 17:30
What are the most commonly found items in the trash according to the municipal solid waste report?
Answers: 1
question
Computers and Technology, 23.06.2019 19:30
Amitha writes up a one-page summary of a novel during her summer internship at a publishing company. when she reads over the page, she realizes she used the word “foreshadow” seven times, and she would like to reduce the repetition. which tool would best amitha solve this problem?
Answers: 3
question
Computers and Technology, 24.06.2019 01:30
Hazel has just finished adding pictures to her holiday newsletter. she decides to crop an image. what is cropping an image?
Answers: 1
question
Computers and Technology, 24.06.2019 10:00
3. what do the terms multipotentialite, polymath, or scanner mean?
Answers: 2
You know the right answer?
Lexical Analyzer Implementation

Use Java to write a simple Lexical Analyzer.

...
Questions
question
Mathematics, 11.03.2021 04:00
question
Mathematics, 11.03.2021 04:00
question
Mathematics, 11.03.2021 04:00
Questions on the website: 13722363