-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScanner.cpp
More file actions
46 lines (35 loc) · 778 Bytes
/
Copy pathScanner.cpp
File metadata and controls
46 lines (35 loc) · 778 Bytes
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
#include "Scanner.h"
#include <iostream>
#include "StateMachine.h"
ScannerClass::ScannerClass(std::string filename){
: mFin.open(filename), mLineNumber = 1
if(!mFin){
exit(1);
}
}
int ScannerClass::GetLineNumber(){
return mLineNumber;
}
TokenClass ScannerClass::GetNextToken(){
StateMachineClass stateMachine;
TokenType t;
std::string lexeme;
MachineState UpdatedState = START_STATE;
char c;
do{
c = mFin.get();
lexeme += c;
UpdatedState = stateMachine.UpdateState(c,t);
if (UpdatedState == START_STATE){
lexeme = "";
if (c == '\n'){
mLineNumber ++;
}
}
}while(UpdatedState != CANTMOVE_STATE);
mFin.unget();
lexeme.pop_back();
TokenClass tc(t,lexeme);
tc.CheckReserved();
return tc;
}