Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The diagram is what the Lexer class should look like This is the state machine that you should build into your lexer: One file must

The diagram is what the Lexer class should look likeimage text in transcribedimage text in transcribedimage text in transcribed

This is the state machine that you should build into your lexer: One file must be called Shank.java. Shank.java must contain main. Your main must ensure that there is one and only one argument (args). If there are none or more than 1 , it must print an appropriate error message and exit. That one argument will be considered as a filename. Your main must then use Files. ReadAllLines to read all of the lines from the file denoted by filename. Your main must instantiate one instance of your Lexer class (to be defined below). You must parse all lines using the lex method of the Lexer class (calling it repeatedly). If lex throws an exception, you must catch the exception, print that there was an exception. You must then print each token out (this is a temporary step to show that it works) once the lexing is complete. One file must be called Token.java. This file must contain a Token class. The token class is made up of an instance of an enum (tokenType) and a value string. There must be a public accessor for both the enum and the value string; the underlying variables must be private. You may create whatever constructors you choose. The enum must be defined as containing values appropriate to what we will be processing. The definition of the enum should be public, but the instance inside Token must be private. We will add to this enum in the next several assignments. You will find it helpful to create an appropriate "ToString" overload. The enum should be inside the Token class so you will reference it as: token.tokenType.WORD The final file must be called Lexer.java. The Lexer class must contain a lex method that accepts a single string and returns nothing. The lex method must use one or more state machine(s) to iterate over the input string and create appropriate Tokens. Any character not allowed by your state machine(s) should throw an exception. The lexer needs to accumulate characters for some types (consider 123 - we need to accumulate 1 , then 2 , then 3 , then the state machine can tell that the number is complete because the next character is not a number). You may not use regular expressions to do your lexical analysis - you must build your own state machine(s)

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

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions