@@ -43,6 +43,9 @@ int Lexer::GetToken(std::ifstream &is) {
4343 } else if (identifier_string_ == " cin" ) {
4444 current_datatype_ = " " ;
4545 ret_token = TOK_CIN;
46+ } else if (identifier_string_ == " main" ) {
47+ current_datatype_ = " " ;
48+ ret_token = TOK_MAIN;
4649 } else {
4750 ret_token = TOK_IDENTIFIER;
4851
@@ -250,6 +253,79 @@ int Lexer::GetToken(std::ifstream &is) {
250253 return TOK_ERROR;
251254}
252255
256+ std::string Lexer::GetTokenType (int token) {
257+ std::string ret_string;
258+ if (token == TOK_INT) {
259+ ret_string = " int" ;
260+ } else if (token == TOK_FLOAT) {
261+ ret_string = " float" ;
262+ } else if (token == TOK_VOID) {
263+ ret_string = " void" ;
264+ } else if (token == TOK_IF) {
265+ ret_string = " if" ;
266+ } else if (token == TOK_ELSE) {
267+ ret_string = " else" ;
268+ } else if (token == TOK_PAREN_OPEN) {
269+ ret_string = " (" ;
270+ } else if (token == TOK_PAREN_CLOSE) {
271+ ret_string = " )" ;
272+ } else if (token == TOK_CURLY_OPEN) {
273+ ret_string = " {" ;
274+ } else if (token == TOK_CURLY_CLOSE) {
275+ ret_string = " }" ;
276+ } else if (token == TOK_COMMA) {
277+ ret_string = " ," ;
278+ } else if (token == TOK_DOT) {
279+ ret_string = " ." ;
280+ } else if (token == TOK_PLUS) {
281+ ret_string = " +" ;
282+ } else if (token == TOK_MINUS) {
283+ ret_string = " -" ;
284+ } else if (token == TOK_DIVIDE) {
285+ ret_string = " /" ;
286+ } else if (token == TOK_MULTIPLY) {
287+ ret_string = " *" ;
288+ } else if (token == TOK_MODULUS) {
289+ ret_string = " %" ;
290+ } else if (token == TOK_SEMICOLON) {
291+ ret_string = " ;" ;
292+ } else if (token == TOK_LEFT_SHIFT) {
293+ ret_string = " <<" ;
294+ } else if (token == TOK_RIGHT_SHIFT) {
295+ ret_string = " >>" ;
296+ } else if (token == TOK_EQUAL_TO) {
297+ ret_string = " ==" ;
298+ } else if (token == TOK_ASSIGNMENT) {
299+ ret_string = " =" ;
300+ } else if (token == TOK_NOT) {
301+ ret_string = " !" ;
302+ } else if (token == TOK_NOT_EQUAL_TO) {
303+ ret_string = " !=" ;
304+ } else if (token == TOK_GREATER_THAN) {
305+ ret_string = " >" ;
306+ } else if (token == TOK_LESS_THAN) {
307+ ret_string = " <" ;
308+ } else if (token == TOK_GREATER_THAN_OR_EQUALS) {
309+ ret_string = " >=" ;
310+ } else if (token == TOK_LESS_THAN_OR_EQUALS) {
311+ ret_string = " <=" ;
312+ } else if (token == TOK_IDENTIFIER) {
313+ ret_string = " identifier" ;
314+ } else if (token == TOK_DECIMAL) {
315+ ret_string = " integer_constant" ;
316+ } else if (token == TOK_FRACTIONAL) {
317+ ret_string = " float_constant" ;
318+ } else if (token == TOK_COUT) {
319+ ret_string = " cout" ;
320+ } else if (token == TOK_CIN) {
321+ ret_string = " cin" ;
322+ } else if (token == TOK_MAIN) {
323+ ret_string = " main" ;
324+ }
325+
326+ return ret_string;
327+ }
328+
253329std::string Lexer::GetCurrentDatatype () { return current_datatype_; }
254330
255331std::vector<std::string> Lexer::GetDuplicateSymbolErrors () { return duplicate_symbol_errors_; }
0 commit comments