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, 22.06.2019 06:00
Which of the following is a way that advancements in technology improve humans' ability to measure air quality and protect human health? a. air quality data gathered by new instruments can be used to reduce exposure to pollutants. b. new technologies enable natural and human-made pollution sources to be located and monitored. c. air quality data gathered by new instruments can be used to predict trends in pollution over time. d. new technologies allow governments to make informed decisions about the regulation of pollution. (choose more than one)
Answers: 2
question
Computers and Technology, 22.06.2019 08:10
Alook-up table used to convert pixel values to output values on a monitor. essentially, all pixels with a value of 190 or above are shown as white (i.e. 255), and all values with a value of 63 or less are shown as black (i.e. 0). in between the pixels are scaled so that a pixel with a value p is converted to a pixel of value 2/127 −+3969). if a pixel has a value of 170 originally, what value will be used to display the pixel on the monitor? if a value of 110 is used to display the pixel on the monitor, what was the original value of the pixel?
Answers: 1
question
Computers and Technology, 22.06.2019 11:00
Which are examples of note-taking tools? check all that recording devices sticky notes digital highlighters paper flags highlighting pens digital displays digital flags
Answers: 1
question
Computers and Technology, 23.06.2019 02:00
Which demographic challenge is europe currently experiencing? a. an aging and decreasing population b. a baby boomc. an unequal distribution between males and females d. a large group of teenagers moving through the school system(i chose a but i'm unsure)
Answers: 1
You know the right answer?
Lexical Analyzer Implementation

Use Java to write a simple Lexical Analyzer.

...
Questions
question
Mathematics, 30.12.2019 21:31
question
History, 30.12.2019 21:31
Questions on the website: 13722359