-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
65 lines (44 loc) · 1.21 KB
/
main.c
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
/*
* main.c file
*/
#include "astblock.h"
#include "stream.h"
#include "context.h"
#include "Parser.h"
#include "Lexer.h"
#include <stdio.h>
int yyparse(AstBlock **tree, yyscan_t scanner);
AstBlock *getAST(const char *expr)
{
AstBlock *tree;
yyscan_t scanner;
YY_BUFFER_STATE state;
if (yylex_init(&scanner)) {
// couldn't initialize
return NULL;
}
state = yy_scan_string(expr, scanner);
if (yyparse(&tree, scanner)) {
// error parsing
return NULL;
}
yy_delete_buffer(state, scanner);
yylex_destroy(scanner);
return tree;
}
int main(void)
{
char parse_test[] = "+my_stream = (1, 2), my_stream <= 3/* comment */, my_stream -> {in + 1} =>";
char closure_test[] = "+class = {=> +local, [local /* stack_id: 1 */] =>}, +closure = class 123, closure[] =>";
char *test = closure_test;
AstBlock *tree = getAST(test);
tree->init();
std::cout << std::endl << std::endl;
std::cout << test << std::endl;
std::cout << tree->to_string() << std::endl;
AstBlock *input = new AstBlock();
input->init();
Stream *output = tree->execute(new Context());
std::cout << output->to_string() << std::endl;
return 0;
}