-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTokenizer.h
30 lines (27 loc) · 900 Bytes
/
Tokenizer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#ifndef TOKENIZER_H
#define TOKENIZER_H
#include <vector>
#include <fstream>
#include "Token.h"
#include "MyExceptions.h"
class Tokenizer{
public:
Tokenizer() : rigaAttuale{ 1 }, nTokenAttuale{ 0 }{}//inizializzo la riga iniziale a 1 e il numero del token a 0
std::vector<Token> operator()(std::ifstream& input) {//implemento l'operatore ()
std::vector<Token> tokens;
tokenizeFile(input, tokens);
if (tokens.size() > 0) {//se c'è almeno un Token la fase di tokenizzazione è andata a buon fine la fase di parsing
return tokens;
}
else {//Se non c'è alcun token allora lancio un eccezione di file vuoto
throw LexicalError("File vuoto");
}
}
private:
int rigaAttuale;
int nTokenAttuale;
void tokenizeFile(std::ifstream& f, std::vector<Token>& tokens);
char leggiCarattere(std::ifstream&);
bool getNextToken(std::ifstream& inputFile, std::stringstream& ssToken);
};
#endif