Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

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

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

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions

Question

Find the binomial coefficient. 1. 6C4 2. 12C3

Answered: 1 week ago

Question

what are the statutory remedy available for members?

Answered: 1 week ago