-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlexer_ut.cpp
More file actions
70 lines (51 loc) · 1.05 KB
/
lexer_ut.cpp
File metadata and controls
70 lines (51 loc) · 1.05 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
#include <string>
#include <iostream>
#include <cassert>
#include <cctype>
#include "lexer.hpp"
void test1();
void test2();
int main()
{
// test all punctuators/operators
test1();
// test keywords
test2();
return 0;
}
void test1()
{
std::string input;
keyword_table kw;
symbol_table sym;
token_ptr t;
input = "% && * () != == = :;\t\t\n";
input += "/ <> <= >= ? -+ ^ !";
input = "false && false";
lexer l( input.begin(), input.end(), kw, sym );
l.lex();
while( t = std::move( l.front() ) )
{
std::cout << t->kind() << '\n';
std::cout << t->print_value() << '\n';
}
}
void test2()
{
std::string input;
keyword_table kw;
symbol_table sym;
token* t;
input = "true false var int bool";
lexer l( input.begin(), input.end(), kw, sym );
// t = l.next();
// assert( t->kind() == "true_kw" );
// t = l.next();
// assert( t->kind() == "false_kw" );
// t = l.next();
// assert( t->kind() == "var_kw" );
// t = l.next();
// assert( t->kind() == "int_kw" );
// t = l.next();
// assert( t->kind() == "bool_kw" );
}