-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostfix.cpp
65 lines (60 loc) · 2.48 KB
/
postfix.cpp
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
#include <llvm/Support/raw_ostream.h>
#include <iostream>
#include "Lexer.h"
using lexer::Lexer;
int
main() {
std::string text, line;
llvm::raw_string_ostream ostream(text);
while (std::getline(std::cin, line))
ostream << line << '\n';
std::cout << std::endl;
std::cout << "in: '" << ostream.str() << "'" << std::endl;
Lexer lex((char *) ostream.str().c_str());
while(true) {
const Lexer::Token& t = lex.Lex();
switch (t.m_type) {
case Lexer::TokenType::TOK_INVALID:
std::cout << "Unsupported token: " << t.m_value.str() << std::endl;
return 1;
case Lexer::TokenType::TOK_LEFT_PARENTHESIS:
std::cout << "( -> " << t.m_value.str() << std::endl;
break;
case Lexer::TokenType::TOK_RIGHT_PARENTHESIS:
std::cout << ") -> " << t.m_value.str() << std::endl;
break;
case Lexer::TokenType::TOK_LEFT_BRACKET:
std::cout << "[ -> " << t.m_value.str() << std::endl;
break;
case Lexer::TokenType::TOK_RIGHT_BRACKET:
std::cout << "] -> " << t.m_value.str() << std::endl;
break;
case Lexer::TokenType::TOK_LEFT_CURLY_BRACKET:
std::cout << "{ -> " << t.m_value.str() << std::endl;
break;
case Lexer::TokenType::TOK_RIGHT_CURLY_BRACKET:
std::cout << "} -> " << t.m_value.str() << std::endl;
break;
case Lexer::TokenType::TOK_LIT_NUMBER:
std::cout << "number: -> " << t.m_value.str() << std::endl;
break;
case Lexer::TokenType::TOK_LIT_STRING:
std::cout << "string: -> " << t.m_value.str() << std::endl;
break;
case Lexer::TokenType::TOK_LIT_BOOL_FALSE:
std::cout << "bool: -> " << t.m_value.str() << std::endl;
break;
case Lexer::TokenType::TOK_LIT_BOOL_TRUE:
std::cout << "bool: -> " << t.m_value.str() << std::endl;
break;
case Lexer::TokenType::TOK_IDENTIFIER:
std::cout << "identifier: -> " << t.m_value.str() << std::endl;
break;
case Lexer::TokenType::TOK_EOF:
return 0;
default:
std::cout << "Unknown token: "<< std::to_string(t.m_type) << t.m_value.str() << std::endl;
return 1;
}
}
}