Question: tokensListing.cpp #include #include #include #include #include #include lex.h //#include ra5.cpp /* * CS280 - Spring 2023 */ using std::map; using namespace std; istream& operator>>(istream& in,

 tokensListing.cpp #include #include #include #include #include #include "lex.h" //#include "ra5.cpp" /*
tokensListing.cpp

#include

#include

#include

#include

#include

#include "lex.h"

//#include "ra5.cpp"

/*

* CS280 - Spring 2023

*/

using std::map;

using namespace std;

istream& operator>>(istream& in, LexItem& tok) {

map StrToTok = {

{"WRITELN", WRITELN},

{ "IF", IF },

{ "ELSE", ELSE },

{ "IDENT", IDENT },

{ "NIDENT", NIDENT },

{ "SIDENT", SIDENT },

{ "ICONST", ICONST },

{ "RCONST", RCONST },

{ "SCONST", SCONST },

{ "PLUS", PLUS },

{ "MINUS" , MINUS },

{ "MULT" , MULT },

{ "DIV" , DIV },

{ "EXPONENT" , EXPONENT },

{ "ASSOP", ASSOP },

{ "NEQ", NEQ },

{ "NGTHAN" , NGTHAN },

{ "NLTHAN", NLTHAN },

{ "CAT", CAT },

{ "SREPEAT" , SREPEAT },

{ "SEQ", SEQ },

{ "SGTHAN", SGTHAN },

{ "SLTHAN", SLTHAN },

{ "COMMA", COMMA },

{ "LPAREN", LPAREN },

{ "RPAREN", RPAREN },

{ "LBRACES", LBRACES },

{ "RBRACES", RBRACES },

{ "SEMICOL", SEMICOL },

{ "ERR",ERR },

{ "DONE", DONE },

};

Token tt;

string tokstr, lexeme, str2;

char ch;

int i, line, strlen;

in >> tokstr ;

if(!in)

{

return in;

}

auto ttitr = StrToTok.find(tokstr);

//cout

if(ttitr != StrToTok.end())

{

tt = ttitr->second;

if(tt == IDENT)

{

in >> lexeme >> line;

tok = id_or_kw(lexeme, line);

}

else if (tt == ICONST || tt == RCONST )

{

in >> lexeme >> line;

LexItem item(tt, lexeme, line);

tok = item;

}

else if (tt == SCONST)

{

in >> strlen;

str2 = ""; i = 0;

ch = in.get();

while (ch != '\"')

{

ch = in.get();

}

ch = in.get();

while ( (ch != '\"') && (i

{

str2 += ch;

ch = in.get();

i++;

}

in >> line;

LexItem item(tt, str2, line);

tok = item;

}

else

{

in >> lexeme >> line;

LexItem item(tt, lexeme, line);

tok = item;

}

}

return in;

}

int main(int argc, char *argv[])

{

LexItem item(ERR, "", 0);

LexItem& tokItem = item;

LexItem kwtok;

ifstream file ;

string str1;

if (argc == 1)

{

cerr

return 0;

}

else

{

if(argv[1][0] == '-')

{

cerr

return 0;

}

file.open(argv[1]);

if( file.is_open() == false ) {

cerr

return 0;

}

}

while (file >> tokItem)

{

cout

}

return 0;

}

lex.h file :

* CS280 - Spring 2023 */ using std::map; using namespace std; istream&

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.epp". Your implementation should include the following in another file, called "RAS.Cpp": - The function Lexitem id_or_kwiconst string\& lexeme, int linenum): id_or_kw 0 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 the keyword Token if it is found. Otherwise. it returns a Lexitem object containing a token for one of the possible types of identifiers (i.e.. IDENT, SIDENT, or NIDENT). - The overloaded operator function operatore for Lexltem. ostream\& operators (ostream\& out, const Lexitem\& tok): The operatoree() 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 es function prints out a Lexitem object information according to the Token value using the following formats

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!