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, 21.06.2019 23:00
Explain briefly why you cannot expect to find a previous version of every file with which you work.
Answers: 1
question
Computers and Technology, 23.06.2019 15:00
Jake really works well with numbers and is skilled with computers but doesn't work well with others. which of the jobs discussed in this unit might be best for jake? why?
Answers: 3
question
Computers and Technology, 23.06.2019 22:30
You draw two cards from a standard deck of 52 cards, but before you draw the second card, you put the first one back and reshuffle the deck. (a) are the outcomes on the two cards independent? why?
Answers: 3
question
Computers and Technology, 24.06.2019 11:00
Why is it uncommon for users to perform searches directly in database tables? a.)users are discouraged from interacting directly with tables because they might confuse tables with spreadsheets. b.) users are discouraged from interacting directly with tables because this may result in unintended changes to source data. c.)users do not have the technical skills required to perform searches directly in database tables. d.)users do not have the permissions required to perform searches directly in database tables.
Answers: 1
You know the right answer?
Lexical Analyzer Implementation

Use Java to write a simple Lexical Analyzer.

...
Questions
question
Mathematics, 05.02.2021 03:40
question
English, 05.02.2021 03:40
Questions on the website: 13722363