-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
78 lines (71 loc) · 2.15 KB
/
main.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
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <iostream>
#include <fstream>
#include "ds/Array.hpp"
#include "ds/String.hpp"
#include "stone/Message.hpp"
#include "ds/ArrayUnitTest.hpp"
#include "ds/StringUnitTest.hpp"
#include "stone/Interpreter.hpp"
#include "stone/MapEnv.hpp"
#include "ds/MapUnitTest.hpp"
#include "stone/Lexer.hpp"
#include "stone/Parser.hpp"
#include "stone/ASTPrinter.hpp"
#include "stone/Data.hpp"
void dsUnitTest() {
ArrayUnitTest::run();
StringUnitTest::run();
}
void stoneTest() {
using namespace stone;
using namespace ds;
std::fstream inputFileStream("test.stone", std::ios::in);
String<> code;
char ch;
while ((ch = inputFileStream.get()) != EOF) {
code.append(ch);
}
std::cerr << code << std::endl;
Lexer *lexer = new Lexer(&code);
Token *token;
String<> descriptor[] = {"Id", "Keyword", "Str", "Num", "Err", "Op", "Sym",};
uint lastLineNumber = 1;
while ((token = lexer->read())) {
if (lastLineNumber != token->lineNumber())
std::cerr << std::endl;
std::cerr << "(" << descriptor[token->type()] << ", " << token->string() << ", " << token->lineNumber() << ", "
<< token->kth() << ")" << " ";
//if (token->type() == Token::OP) {
//if (((OpToken*)token)->getOperator(2))
//std::cerr << ((OpToken*)token)->getOperator(2)->type() << std::endl;
//}
lastLineNumber = token->lineNumber();
}
// parse
cerr << endl << endl;
lexer = new Lexer(&code);
MsgHandler *msgHandler = new MsgPrinter(std::cerr);
Parser *parser = new Parser(lexer, msgHandler);
AST *ast = parser->parse();
cerr << endl;
ASTVisitor *visitor = new ASTPrinter(std::cerr);
if (!ast)cerr << "null ast" << endl;
ast->accept(visitor);
cerr << endl;
// interpret
//shared_ptr<Env> env(new MapEnv(nullptr, nullptr));
Interpreter *interpreter = new Interpreter();
ast->accept(interpreter);
}
int main() {
using namespace std;
// ArrayUnitTest::run();
// StringUnitTest::run();
//MapUnitTest::run();
stoneTest();
//stoneParserTest();
//visitorTest();
//stoneLexerTest();
//test();
return 0;
}