forked from rperlste/UniversalCompiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScanner.h
57 lines (47 loc) · 1.52 KB
/
Scanner.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef _scanner
#define _scanner
#include <fstream>
#include <iostream>
#include <string>
#include "Action.h"
#include "State.h"
#include "Token.h"
#include "TransitionTable.h"
#include "CharacterSet.h"
/*****************************************************
* Scanner *
* The Scanner class reads a file and is used to *
* extract Tokens within that file, and report any *
* errors it has detected, such as illegal grammar. *
*****************************************************/
class Scanner{
public:
Scanner( std::fstream* );
Token scannerDriver();
Token scan();
Token peekNextToken();
Token getPreviousToken();
int getScannerFilePosition() const;
std::fstream* getProgramFile() const;
bool isDoneScanning();
bool hasError();
void close();
private:
char getCurrentChar();
char peekNextChar();
void consumeChar();
Action::Action getAction( State::State, char );
State::State getNextState( State::State, char );
TokenEnums lookupCode( State::State, char );
void checkExceptions( Token& );
void LexicalError( std::string );
int filePosition;
bool errorDetected;
bool isClosed;
Token* tokenBuffer;
Token currentToken;
Token previousToken;
char* charBuffer;
std::fstream* programFile;
};
#endif