Answered step by step
Verified Expert Solution
Link Copied!

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 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.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Flash XML Applications Use AS2 And AS3 To Create Photo Galleries Menus And Databases

Authors: Joachim Schnier

1st Edition

0240809173, 978-0240809175

More Books

Students also viewed these Databases questions