Tokenizer.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #ifndef TOKENIZER_H
  2. #define TOKENIZER_H
  3. #include "Token.h"
  4. #include "DoubleToken.h"
  5. #include "StringToken.h"
  6. #include <vector>
  7. #include <memory>
  8. using namespace std;
  9. class Tokenizer
  10. {
  11. public:
  12. Tokenizer();
  13. void tokenize(vector<unique_ptr<Token>>& tokens, vector<unique_ptr<istream>>& streams);
  14. private:
  15. int next();
  16. int peek();
  17. bool next(char c);
  18. void add(TokenType type);
  19. void add(TokenType type, double data);
  20. void add(TokenType type, string data);
  21. void add(char c, TokenType t1, TokenType t2, TokenType t3, TokenType t4);
  22. void handleChar(int c);
  23. void handleLiteral(int c, TokenType type);
  24. void handleNumber(int c);
  25. void handleSpecial(int c);
  26. void handleString();
  27. void handleSlash();
  28. void handleOneLineComment();
  29. void handleMultiLineComment();
  30. bool isLetter(int c);
  31. bool isDigit(int c);
  32. bool isValidNamePart(int c);
  33. int buffer;
  34. unsigned int line;
  35. vector<unique_ptr<Token>>* tokens;
  36. unsigned int streamIndex;
  37. vector<unique_ptr<istream>>* streams;
  38. };
  39. #endif