Question: You are given a copy of lex.h from Programming Assignment 1 , and a file called tokensListing.cpp as a driver program. DO NOT

You are given a copy of "lex.h" from Programming Assignment 1, and a file called "tokensListing.cpp" as a driver program.
DO NOT CHANGE neither "lex.h" nor "tokensListing.cpp".
Your implementation should include the following in another file, called "RA5.cpp":
The function (from PA 1)
Lexltem id_or_kw(const string& lexeme, int linenum);
Id_or_kw function accepts a reference to a string of identifier lexeme (i.e., keyword, or IDENT) and a line number and returns a Lexltem object. It searches
for the lexeme in a directory that maps a string value of a keyword to its corresponding Token value, and it returns a Lexltem object containing the lexeme,
the keyword Token, and the line number, if it is found, or IDENT Token otherwise.
The overloaded operator function operator for printing out an object of Lexltem class (defined in "lex.h").
ostream& operator (ostream& out, const Lexltem& tok);
The operator () function accepts a reference to an ostream object and a reference to a Lexltem object, and returns a reference to the ostream object. The
operator function prints out a Lexltem object information according to the Token value using the following formats:
Token
Format
IDENT
IDENT: 'lexeme'
Keyword token
Keyword-Token: Keyword
ICONST/ RCONST
Token: (lexeme)
SCONST
SCONST: "lexeme"
Operators
Op-Token: Operator Symbol "lexeme"
delimiters
Delimiter-Token: Delimiter Character "lexeme"
ERR
ERR: {lexeme} Error at Line no. linenumber
Where, "linenumber" is the value of the line number, "lexeme" is the lexeme string value.
Note that the implementation of operator function in RA5 differs from its implementation in PA 1. See the examples in the class slides for the output
format.
Use the given driver program in "tokensListing.cpp" for testing your implementations, where the driver program would accept a file name as a command line
argument for a test case in each run. Note, there are 4 test cases in RA 5. See the details of the outputs for the examples in the slides.
 You are given a copy of "lex.h" from Programming Assignment 1,

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!