Question: DO NOT CHANGE lex.h (use the one here not a new one) lex.h: #ifndef LEX_H_ #define LEX_H_ #include #include #include using namespace std ; //Definition

DO NOT CHANGE lex.h (use the one here not a new one)

lex.h:#ifndef LEX_H_#define LEX_H_#include #include #include using namespace std;//Definition of all the possible token typesenum Token {// keywordsPROGRAM, PRINT, READ, INTEGER, END, IF, THEN, REAL, CHAR,// an identifierIDENT,// an integer and string constantICONST, RCONST, SCONST,// the operators, parens, semicolonPLUS, MINUS, MULT, DIV, ASSOP, LPAREN, RPAREN, COMA,EQUAL, LTHAN, CONCAT, COLON,// any error returns this tokenERR,// when completed (EOF), return this tokenDONE};static mapstring> tokenPrint = {{PROGRAM, "PROGRAM"},{READ, "READ"},{INTEGER, "INTEGER"},{REAL, "REAL"},{CHAR, "CHAR"},{ PRINT, "PRINT" },{ IF, "IF" },{ END, "END" },{THEN, "THEN"},{ 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 mapstring,Token> kwmap = {{"PROGRAM", PROGRAM},{"READ", READ},{ "INTEGER", INTEGER},{ "REAL", REAL},{ "CHAR", CHAR},{ "PRINT", PRINT },{ "IF", IF },{"THEN", THEN},{ "END", END },};//Class definition of LexItemclass LexItem {Tokentoken;stringlexeme;intlnum;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; }TokenGetToken() const { return token; }stringGetLexeme() const { return lexeme; }intGetLinenum() const { return lnum; }};extern ostream& operatorconst LexItem& tok);extern LexItem id_or_kw(const string& lexeme, int linenum);extern LexItem getNextToken(istream& in, int& linenum);#endif /* LEX_H_ */

ALSO YOU CAN USE THIS TO HELP YOU:

DO NOT CHANGE lex.h (use the one here not a new one)

X Begin isalpha(c) isdigitc = = T' =='V InInt isdigit(c) InComment c!= 'n' Inident isalnum(c) C == V InPossibleReal InDoubleString nSingleString else else check for keywords Remember to putback isdigit(c) else Don't forget to putback! c == \\\\' (== \\\\' Remember to putback! InReal isdigit(c) PossibleConcat PossibleEquals else else else Don't forget to putback! C == 1/ make sure to (='=' putback make sure to putback! Return

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 Programming Questions!