Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Build an ad-hoc scanner in Java for a calculator language. As output, have it pr

ID: 672165 • Letter: B

Question

Build an ad-hoc scanner in Java for a calculator language. As output, have it print a list, in order,

of the input tokens. For simplicity, feel free to halt in the case of a lexical error.

Tokens for the calculator language are as follows:

assign -> :=

plus -> +

minus -> -

times -> *

div -> /

lparen -> (

rparen -> )

id -> letter ( letter | digit ) *

excluding read and write

number -> digit digit * | digit * ( . digit | digit . ) digit *

comment -> /* (non-* | * non-/ )* */ | // (non-newline* newline

where non-*, non-/, and non-newline are shorthand representations for the alternatives of all characters

other than *, /, and newline, respectively.

Sample input might be: number := a + b

total := (a – b) * c

final := total + num

LexTest := )) a - b

__________________________________________________________________________________

The cat function on eve can be used to catalog (list) your source file, compile, and output. To capture

output to your screen, at the eve prompt enter the following:

$ startrec filename

which will start recording all the output on the screen to the filename you have specified.

$ cat filename.extension will list the entire file on your console. This is one way to display your

source file entirely, and then run it, capturing all the detail.

When you are done, at the eve prompt, enter Control-D and the file you’ve designated will be closed,

and available for printing.

Explanation / Answer

My Solution:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote