Question
LEX.H /* * lex.h * * CS280 * Spring 2021 */ #ifndef LEX_H_ #define LEX_H_ #include #include #include using std::string; using std::istream; using std::ostream; using
LEX.H
/* * lex.h * * CS280 * Spring 2021 */
#ifndef LEX_H_ #define LEX_H_
#include
//Definition of all the possible token types enum Token { // keywords PROGRAM, PRINT, READ, INTEGER, END, IF, THEN, REAL, CHAR,
// an identifier IDENT,
// an integer, real, and string constant ICONST, RCONST, SCONST,
// the operators, parens, semicolon PLUS, MINUS, MULT, DIV, ASSOP, LPAREN, RPAREN, COMA, EQUAL, LTHAN, CONCAT, COLON, // any error returns this token ERR,
// when completed (EOF), return this token DONE };
static map
{ IDENT, "IDENT" },
{ ICONST, "ICONST" }, { RCONST, "RCONST" }, { SCONST, "SCONST" }, { PLUS, "PLUS" }, { MINUS, "MINUS" }, { MULT, "MULT" }, { DIV, "DIV" }, { ASSOP, "ASSOP" }, { LPAREN, "LPAREN" }, { RPAREN, "RPAREN" }, { COLON, "COLON" }, {COMA, "COMA" }, { EQUAL, "EQUAL" }, { LTHAN, "LTHAN" }, { CONCAT, "CONCAT" }, { ERR, "ERR" },
{ DONE, "DONE" }, };
static map
//Class definition of LexItem class LexItem { Token token; string lexeme; int lnum;
public: LexItem() { token = ERR; lnum = -1; } LexItem(Token token, string lexeme, int line) { this->token = token; this->lexeme = lexeme; this->lnum = line; }
bool operator==(const Token token) const { return this->token == token; } bool operator!=(const Token token) const { return this->token != token; }
Token GetToken() const { return token; } string GetLexeme() const { return lexeme; } int GetLinenum() const { return lnum; } };
extern ostream& operator
#endif /* LEX_H_ */
TokensListing.cpp
#include
/* * CS280 - Spring 2021 */
#include
using namespace std;
int main(int argc, char *argv[]) { LexItem tok; LexItem kwtok; LexItem idtoks[] = { LexItem(IDENT,"PRINT",3), LexItem(IDENT,"circle",3), LexItem(IDENT,"square",11), LexItem(IDENT,"rectangle",12), LexItem(IDENT,"ellipse",14), LexItem(IDENT, "PROGRAM", 1), LexItem(IDENT, "READ", 8), LexItem(IDENT, "INTEGER",2), LexItem(IDENT, "REAL",3), LexItem(IDENT, "CHAR",4), LexItem(IDENT, "IF", 5), LexItem(IDENT, "THEN", 5), LexItem(IDENT, "END", 0) }; LexItem toks[] = { LexItem(END,"END",15), LexItem(ICONST,"579",5), LexItem(SCONST,"hello NJIT",6), LexItem(RCONST,"5.79",7), LexItem(PLUS,"+",3), LexItem(MINUS,"-",3), LexItem(MULT,"*",3), LexItem(DIV,"/",3), LexItem(ASSOP,"=",3), LexItem(LPAREN,"(",3), LexItem(RPAREN,")",3), LexItem(COLON,":",3), LexItem(COMA,",",3), LexItem(COMA,",",3), LexItem( EQUAL, "EQUAL", 4), LexItem( LTHAN, "LTHAN", 4 ), LexItem( CONCAT, "CONCAT", 6 ), LexItem(ERR, "ERR", 3), LexItem(DONE,"DONE",3), }; bool idsflag = false; bool tokflag = false; int i; if (argc == 1) { cerr
Please read all the given instruction
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"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); The overloaded operator function operatorStep 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