// Integer arithmetic interpreter lexeme declaration. // // File: lexeme.h // Author: course // Version: 2 // // This file declares the arithmetic interpreter lexeme // type, or lexeme. #ifndef _LEXEME_H_ #define _LEXEME_H_ // Constants that one may want to change: // // Maximum length of symbol. // const int MAX_SYMBOL_LENGTH = 100; #include "avalue.h" // Arithmetic interpreter value // type definition, >> operator, // and << operator. // Character constants: // const char PLUS_SIGN = '+'; const char MINUS_SIGN = '-'; const char TIMES_SIGN = '*'; const char DIVIDE_SIGN = '/'; const char EQUAL_SIGN = '='; const char LEFT_PAREN = '('; const char RIGHT_PAREN = ')'; const char SEMICOLON = ';'; const char EOF_MARKER = '.'; // Operator types: // enum optype { OP_PLUS, OP_MINUS, OP_TIMES, OP_DIVIDE }; // Lexeme Types: // enum lextype { LEX_SYMBOL, LEX_NUMBER, LEX_OP, LEX_ASSIGN, LEX_EOF, LEX_LEFT_PAREN, LEX_RIGHT_PAREN, LEX_SEMICOLON }; // Lexemes: // class lexeme_class; typedef lexeme_class * lexeme; // Lexeme_classes: // class lexeme_class { public: lextype type; // See above for lexeme types. char * pname; // Print name if LEX_SYMBOL. optype op; // Operator type if LEX_OP. avalue value; // Value if LEX_NUMBER. // Possible value if LEX_SYMBOL. bool inited; // True for LEX_SYMBOL if value // has been set; else false. lexeme next; // For LEX_SYMBOL, pointer to // next symbol in symbol table. }; // Output a lexeme to a stream: s << l where s is // typically cout. // ostream& operator << (ostream& s, lexeme l); // Input lexeme from a stream: s >> l where s is // typically ein. // // Remove preceding space. If end of stream, // return l = NULL. On other errors, call error. // istream& operator >> (istream& s, lexeme& l); // Functions to read lexemes from ein. // Initialize lexeme reader (i.e. initialize symbol // table). // void init_lexemes(void); // Test to see if there are no more lexemes in input // stream ein. // bool end_lexemes(void); // Get the next lexeme from the input stream ein. // lexeme get_lexeme(void); // Backup over last lexeme gotten. // void unget_lexeme(void); // Flush line of lexemes (e.g. after error). // void flush_lexemes(void); #endif // _LEXEME_H_