Page 1 of 1 File Input Assignment Assignment objective: Begin implementing a lexical analyzer by first writing the code to read from a text file one line at a time and printing each line one character...

1 answer below »
Attached are the files for the project, followed by a PDF with the assignment instructions, and a JPG with a picture of the Lexemes that needs to be implemented in the code. most of the code is completed for the most part, the only thing that is left to do is to implement what is shown in the JPG. The final code should be able to read through something on a txt file that looks like this " x:=abe1*f+((e-c)/4)+556"


Page 1 of 1 File Input Assignment Assignment objective: Begin implementing a lexical analyzer by first writing the code to read from a text file one line at a time and printing each line one character at a time. Design: 1. Download the files Assignment1.cpp, LexicalAnalyzer.cpp, LexicalAnalyzer.h provided along with this assignment in Blackboard and include them in your project. 2. The file Assignment1.cpp is the driver code for the assignment. The main function receives, via the command line argument, the name of the text file that the lexical analyzer processes. The main function contains a loop to call the lexical analyzer’s getChar method to get the next character and print it out. The loop terminates when the lexical analyzer method isEOF returns true. You cannot modify any of the code in this file. 3. LexicalAnalyzer is the lexical analyzer’s class. Right now, the lexical analyzer is not complete, with only the methods to read from a text file. Remember, a source code program file for a programming language is just a text file. Implement the code for the methods: isEOF(), getChar(), and readNextLine() by adding the necessary code to the files LexicalAnalyzer.cpp and LexicalAnalyzer.h. You cannot change any of the code that is already in those files, but you can add code anywhere within those two files. But, you must declare private, all the data members you add to the lexical analyzer class by adding them under private: in the file LexicalAnalyzer.h, and you do not need to add any methods to the lexical analyzer class in this assignment. 4. The isEOF() method returns true when the lexical analyzer reaches the end of the text file; otherwise the method returns false. 5. The getChar() method returns the next character from the current line stored in the lexical analyzer. When this method attempts to get the next character after the last character (newline character) on the line, then this method calls the readNextLine() method. 6. The readNextLine() method attempts to read only the next line from the text file and storing the line as a string within the lexical analyzer. The readNextLine() method needs to recognize when it reaches the end of the file when attempting to read the next line of the text file. 7. The lexical analyzer stores (within itself) the position number (within the current line) of the character returned by the last call to the getChar() method. The lexical analyzer also stores (within itself) the character returned by the last call to the getChar() method. 8. The command to launch your program, assuming test.txt contains several lines of text and the name of the executable code of your program is a.out, is: a.out test.txt 9. Do NOT type any comments in your program. If you do a good job of programming, then it will be easy for me to determine the task of your code.
Answered 2 days AfterMar 01, 2022

Answer To: Page 1 of 1 File Input Assignment Assignment objective: Begin implementing a lexical analyzer by...

Vaibhav answered on Mar 03 2022
116 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here