Answered step by step
Verified Expert Solution
Question
1 Approved Answer
You must submit .java files. Any other file type will be ignored. Especially .class files. You must not zip or otherwise compress your assignment. Blackboard
You must submit .java files. Any other file type will be ignored. Especially .class" files. You must not zip or otherwise compress your assignment. Blackboard will allow you to submit multiple files. You must submit buildable.java files for credit. This assignment must have three different source code files. One file must be called Basic.java. Basic.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 File. 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) for each line from ReadAllLines. You must parse each line using the lex method of the Lexer class. You must take the list of tokens from lex and concatenate it to a single list. If lex throws an exception, you must catch the exception, print that there was an exception and lex the next line. 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 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 final file must be called Lexer.java. The Lexer class must contain a lex method that accepts a single string and returns a collection (array or list) of Tokens. 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. For this assignment, the allowable input consists of basic mathematical symbols and numbers such as you might find in Java. +, -, *, / and both positive and negative numbers, including decimals. Allow but ignore spaces/tabs. At the end of each line, add an EndOfLine token. You must submit .java files. Any other file type will be ignored. Especially .class" files. You must not zip or otherwise compress your assignment. Blackboard will allow you to submit multiple files. You must submit buildable.java files for credit. This assignment must have three different source code files. One file must be called Basic.java. Basic.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 File. 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) for each line from ReadAllLines. You must parse each line using the lex method of the Lexer class. You must take the list of tokens from lex and concatenate it to a single list. If lex throws an exception, you must catch the exception, print that there was an exception and lex the next line. 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 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 final file must be called Lexer.java. The Lexer class must contain a lex method that accepts a single string and returns a collection (array or list) of Tokens. 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. For this assignment, the allowable input consists of basic mathematical symbols and numbers such as you might find in Java. +, -, *, / and both positive and negative numbers, including decimals. Allow but ignore spaces/tabs. At the end of each line, add an EndOfLine token
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started