Your implementation should include the following in another file
Ask Expert

Be Prepared For The Toughest Questions

Practice Problems

Your implementation should include the following in another file

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

LexItem id_or_kw(const string& lexeme, int linenum);

id_or_kw () function accepts a reference to a string of a lexeme and a line number and returns a LexItem 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 LexItem object containing either the keyword Token if it is found, or the identifier token IDENT if not.

• The overloaded operator function operator<< for LexItem.

ostream& operator<<(ostream& out, const LexItem& tok);

The operator<<() function accepts a reference to an ostream object and a reference to a LexItem object, and returns a reference to the ostream object. The operator<< function should print out the string value of the Token in the tok object, followed by its lexeme and line number.

Note that the implementation of operator<< function in RA5 differs from its implementation in PA1. See the examples below for the output format.

Use the given driver program in “tokensListing.cpp” for testing your implementations. The driver program accepts two command line arguments, “-othertok” and “-idsonly”.

The “-othertok” flag is used to test your implementation of the overloaded operator<< function only, and the “-idsonly” is used to test your implementation of both functions. See the details of the outputs for the examples in the slides.

Video

complexnumbers.cpp

idsonly.correct

othertok.correct

Hint
ComputerAn overloaded operator is called an operator function. You declare an operator function with the keyword operator preceding the operator. Overloaded operators are distinct from overloaded functions, but like overloaded functions, they are distinguished by the number and types of operands used with the operator. The function call operator () can be overloaded for objects of class type. When...

Know the process

Students succeed in their courses by connecting and communicating with
an expert until they receive help on their questions

1
img

Submit Question

Post project within your desired price and deadline.

2
img

Tutor Is Assigned

A quality expert with the ability to solve your project will be assigned.

3
img

Receive Help

Check order history for updates. An email as a notification will be sent.

img
Unable to find what you’re looking for?

Consult our trusted tutors.

Developed by Versioning Solutions.