-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser_test.cpp
More file actions
45 lines (41 loc) · 1.37 KB
/
parser_test.cpp
File metadata and controls
45 lines (41 loc) · 1.37 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
#include <iostream>
#include <string>
#include <map>
#include "Purah.hpp"
using namespace purah;
void print(std::vector<tkn::Token> vec) {
std::cout << vec[0].line << ": ";
unsigned int i{};
for(tkn::Token& token : vec)
std::cout << (i++ ? ", <" : "<") << token.type << " '" << token.value << "'>";
std::cout << std::endl;
}
const std::map<nds::ASTNodeType, std::string> keywords{
{nds::SimpleAST,"SimpleAST"},
{nds::NewVarNodeType,"NewVarNodeType"},
{nds::IdentifierExprType,"IdentifierExprType"},
{nds::IntExprType,"IntExprType"},
{nds::FloatExprType,"FloatExprType"},
{nds::BoolExprType,"BoolExprType"},
{nds::StringExprType,"StringExprType"},
{nds::BinaryExprType,"BinaryExprType"},
{nds::CallExprType,"CallExprType"},
{nds::COUTExprType,"COUTExprType"}
};
int main() {
std::string input{};
std::string str{};
unsigned int line{};
while(true) {
std::getline(std::cin,str);
if(str == "quit") break;
input += str + '\n';
}
std::vector<tkn::Token> tokens = lxr::Lexer{}(input);
print(tokens);
std::vector<nds::ASTPtr>&& ast = prsr::Parser{tokens}();
std::cout << "Parsed " << ast.size() << " nodes." << std::endl;
for(unsigned int i{}; i < ast.size(); ++i)
std::cout << i <<". Node type: " << keywords.at(ast.at(i)->nodeType()) << std::endl;
return 0;
}