Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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 RAcpp:
The function from PA
Lexltem idorkwconst string& lexeme, int linenum;
Idorkw function accepts a reference to a string of identifier lexeme ie 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
KeywordToken: Keyword
ICONST RCONST
Token: lexeme
SCONST
SCONST: "lexeme"
Operators
OpToken: Operator Symbol "lexeme"
delimiters
DelimiterToken: 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 RA differs from its implementation in PA 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 test cases in RA See the details of the outputs for the examples in the slides.
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