Question: A c++ program using the following code /* * tokens.h * * */ #ifndef TOKENS_H_ #define TOKENS_H_ #include #include using std::string; using std::istream; using std::ostream;
A c++ program using the following code
/* * tokens.h * * */ #ifndef TOKENS_H_ #define TOKENS_H_ #include #include using std::string; using std::istream; using std::ostream; enum TokenType { // keywords PRINT, IF, THEN, TRUE, FALSE, // an identifier IDENT, // an integer and string constant ICONST, SCONST, // the operators, parens and semicolon PLUS, //+ MINUS, //- STAR, //* SLASH, // / ASSIGN, / = EQ, NEQ, LT, // < LEQ, GT, //> GEQ, LOGICAND, LOGICOR, LPAREN, //( RPAREN, // ) SC, // ; // any error returns this token ERR, // when completed (EOF), return this token DONE }; class Token { TokenType tt; string lexeme; int lnum; public: Token() { tt = ERR; lnum = -1; } Token(TokenType tt, string lexeme, int line) { this->tt = tt; this->lexeme = lexeme; this->lnum = line; } bool operator==(const TokenType tt) const { return this->tt == tt; } bool operator!=(const TokenType tt) const { return this->tt != tt; } TokenType GetTokenType() const { return tt; } string GetLexeme() const { return lexeme; } int GetLinenum() const { return lnum; } }; extern ostream& operator<<(ostream& out, const Token& tok); extern Token getNextToken(istream *in, int *linenum); #endif /* TOKENS_H_ */ I need help with a program that will look through a command line argument for a file, if it is a file read the file character by character and decide what tyoe of token it is, So it will test just for these characters + , - , * , / , ( , ) , ; , = , > , < , Once it identifies one character, move on to the next one then when the file is done it will return token type DONE, if there is an error it will return ERR. Use the code above to print out the token type. I have labled the name with the operand it stands for, only need the operands i described above.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
