/*************************************************************** * * * Scanner class for Aho and Ullman's Pascal subset * * * * Written by : Nancy Ide * * * ***************************************************************/ #ifndef SCANNER_H #define SCANNER_H #define EQ == #define NE != /* TOKEN_LIST macro is used to generate an enumerated list of token types as well as a string array containing each token name -- makes modifying the token list easier. */ // Token types returned by the scanner and used by the parser #define TOKEN_LIST T(T_program), // Program keyword T(T_begin), // Begin keyword T(T_end), // End T(T_var), // Var keyword T(T_function), // Function keyword T(T_procedure), // Procedure keyword T(T_result), // Result keyword T(T_integer), // Integer keyword T(T_real), // Real keyword T(T_array), // Array keyword T(T_of), // Of keyword T(T_if), // If keyword T(T_then), // Then keyword T(T_else), // Else keyword T(T_while), // While keyword T(T_do), // Do keyword T(T_not), // Not keyword T(T_identifier), // Identifier T(T_constant), // Constant (integer or real number) T(T_relop), // Relop("=", "<> ", "< ", "> ", "< =", "> =" ) T(T_mulop), // Mulop("*", "/", "div","mod", "and") T(T_addop), // Addop("+", "-", "or") T(T_assignop), // Assignment operator (";=") T(T_comma), // Comma T(T_semicolon), // Semicolon T(T_colon), // Colon T(T_rightparen), // Right parenthesis T(T_leftparen), // Left parenthesis T(T_rightbracket), // Right bracket T(T_leftbracket), // Left bracket T(T_unaryminus), // Unary minus T(T_unaryplus), // Unary plus T(T_doubledot), // Doubledot ("..") T(T_endmarker), // End of program marker (".") T(T_eof) // End of file marker /* * Define the enumerated list of tokens. * Uses a trick with T macro and TOKEN_LIST */ #define T(name) name // Define T() as the name enum TOKEN_TYPE { TOKEN_LIST }; #undef T // Remove temporary macro // A list of the names of the tokens extern const char *const TOKEN_NAMES[] = { ... // fill in as appropriate #endif