-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLexerTest2.cpp
More file actions
91 lines (70 loc) · 1.86 KB
/
LexerTest2.cpp
File metadata and controls
91 lines (70 loc) · 1.86 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <assert.h>
#include <iostream>
#include <vector>
#include <map>
#include "FileLexer.h"
#include "Type.h"
#include "Expression.h"
#include "CompilerHelpers.h"
#include "logging.h"
using namespace QLang;
using namespace std;
vector<pair<int, string> > gSymbolList;
int main( int argc, char *argv[] )
{
if ( argc < 2 )
{
cerr << argv[ 0 ] << " [filename]" << endl;
return -1;
}
LexerReader reader( argv[ 1 ] );
Lexer l( &reader );
int sym;
for( int i = 0; i < 10; i++ )
{
sym = l.getSymbol();
}
//sym = l.peekSymbol();
int pos = l.getCurrentPos();
if ( pos != 10 )
{
cout << "Failed to get proper position" << endl;
return -1;
}
for( int i = 0; i < 10; i++ )
{
sym = l.getSymbol();
gSymbolList.push_back( pair<int, string>( sym, l.getSymbolText() ) );
if ( sym < Lexer::NUM_SYMBOLS )
std::cout << "-Symbol (" << i << ") " << sym << " (" << l.getSymbolText() << ")" << std::endl;
else
std::cout << "-Symbol (" << i << ") " << (char)sym << std::endl;
}
l.setCurrentPos( pos );
for( int i = 0; i < 10; i++ )
{
sym = l.getSymbol();
if ( sym < Lexer::NUM_SYMBOLS )
std::cout << "+Symbol (" << i << ") " << sym << " (" << l.getSymbolText() << ")" << std::endl;
else
std::cout << "+Symbol (" << i << ") " << (char)sym << std::endl;
if ( gSymbolList[ i ].first != sym or
gSymbolList[ i ].second != l.getSymbolText() )
{
cerr << "Failded to match on " << i << "nth symbol" << endl;
return -1;
}
}
l.setCurrentPos( 2 );
for( int i = 0; i < 10; i++ )
{
sym = l.getSymbol();
gSymbolList.push_back( pair<int, string>( sym, l.getSymbolText() ) );
if ( sym < Lexer::NUM_SYMBOLS )
std::cout << "Symbol (" << i << ") " << sym << " (" << l.getSymbolText() << ")" << std::endl;
else
std::cout << "Symbol (" << i << ") " << (char)sym << std::endl;
}
cout << "Test passed" << endl;
return 0;
}