00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef SCANNER_H
00021 #define SCANNER_H
00022
00023 #include "config.h"
00024
00025 #ifndef BUILDING_DOX
00026 # include <iostream>
00027 # include <string>
00028 #endif
00029
00033 enum EToken {
00034 ETOKEN_NULL = 0,
00035
00036
00037 ETOKEN_ID,
00038 ETOKEN_NUMBER_INT,
00039 ETOKEN_NUMBER_DOUBLE,
00040 ETOKEN_STRING,
00041
00042
00043 ETOKEN_OP_LCBR,
00044 ETOKEN_OP_RCBR,
00045 ETOKEN_OP_LPAR,
00046 ETOKEN_OP_RPAR,
00047 ETOKEN_OP_STAR,
00048 ETOKEN_OP_SLASH,
00049 ETOKEN_OP_PLUS,
00050 ETOKEN_OP_MINUS,
00051 ETOKEN_OP_LESS,
00052 ETOKEN_OP_LESS_EQ,
00053 ETOKEN_OP_GREATER,
00054 ETOKEN_OP_GREATER_EQ,
00055 ETOKEN_OP_ASSIGN,
00056 ETOKEN_OP_COMMA,
00057 ETOKEN_OP_SEMICOLON,
00058
00059
00060 ETOKEN_KW_AND,
00061 ETOKEN_KW_DIV,
00062 ETOKEN_KW_DOUBLE,
00063 ETOKEN_KW_ELSE,
00064 ETOKEN_KW_EQ,
00065 ETOKEN_KW_IF,
00066 ETOKEN_KW_INT,
00067 ETOKEN_KW_NEQ,
00068 ETOKEN_KW_NOT,
00069 ETOKEN_KW_OR,
00070 ETOKEN_KW_STRING,
00071 ETOKEN_KW_VAR,
00072 ETOKEN_KW_VOID,
00073 ETOKEN_KW_WHILE,
00074 };
00076 std::ostream& operator<<(std::ostream &, EToken);
00077
00081 struct Token {
00082 EToken type;
00083 int lineno;
00084
00085 int numberInt;
00086 double numberDouble;
00087 std::string text;
00088
00089 Token():
00090 type(ETOKEN_NULL),
00091 lineno(0),
00092 numberInt(0),
00093 numberDouble(0.0)
00094 {
00095 }
00096 Token(EToken type_, int lineno_, int numberInt_, double numberDouble_, const std::string &text_):
00097 type(type_),
00098 lineno(lineno_),
00099 numberInt(numberInt_),
00100 numberDouble(numberDouble_),
00101 text(text_)
00102 {
00103 }
00104 };
00106 std::ostream& operator<<(std::ostream &, const Token &);
00107
00111 class IErrorSensitive {
00112 public:
00113 virtual ~IErrorSensitive() { }
00117 virtual bool hasError() const = 0;
00118 };
00119
00123 class IScanner: public IErrorSensitive {
00124 public:
00125 virtual ~IScanner() { }
00131 virtual bool readNext(Token &token) = 0;
00132 };
00133
00137 class ScannerFactory {
00138 public:
00146 static IScanner* createScanner(std::istream &input, std::string fileName);
00147 private:
00148 ScannerFactory();
00149 };
00150
00151 #endif