Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

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 »

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 cu
ent 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 cu
ent line) of the character returned
y the last call to the getChar() method. The lexical analyzer also stores (within itself) the character returned
y 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 After Mar 01, 2022

Solution

Vaibhav answered on Mar 03 2022
103 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