-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlparser.cc
More file actions
114 lines (89 loc) · 2.33 KB
/
Copy pathlparser.cc
File metadata and controls
114 lines (89 loc) · 2.33 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include <string>
#include <iostream>
#include <FlexLexer.h>
#include "lua_driver.hh"
extern char *yytext;
extern int yylineno;
int lineno = 1;
int oper(const std::string &op, ...) {
// std::cout << "oper " << yytext << std::endl;
return -2;
}
void nextline() {
++lineno;
// std::cout << "line " << std::endl;
}
void yyerror(const char *s) {
// fprintf(stdout, "%s\n", s);
std::cout << "lineno: " << lineno << " e: " << s << std::endl;
}
void execute(int i) {
std::cout << "execute " << i << std::endl;
}
int seq(int,int) {
std::cout << "seq " << std::endl;
return -3;
}
int name(int i) {
// std::cout << "name: " << yytext << " " << i << std::endl;
return -i;
}
void comment(const std::string &comment) {
std::cout << "comment: " << comment << std::endl;
}
void linecomment(const std::string &comment) {
std::cout << "linecomment: " << comment << std::endl;
}
int yyparse ();
extern int yydebug;
void printAndClauses(Node *clause) {
if (not clause->is<BinExpression>()) {
std::cout << clause->toString() << std::endl;
return;
}
auto bin = clause->as<BinExpression>();
if (bin->getOp()->toString() == "and") {
printAndClauses(bin->getLeft());
printAndClauses(bin->getRight());
} else {
std::cout << clause->toString() << std::endl;
/*
std::cout << bin->getOp()->toString() << ": " << std::endl <<
" left: " << bin->getLeft()->toString() << std::endl <<
"right: " << bin->getRight()->toString() << std::endl
;
*/
}
}
int main(int argc, char* argv[]) {
// yyparse();
lua_driver driver;
driver.parse( argv[1] );
/*for(auto p : driver.getNodes()) {
std::cout << p->toString() << std::endl;
}*/
for( auto p : driver.getExpressionNodes() ) {
if ( p->is<IfBlock>() ) {
auto ifb = p->as<IfBlock>();
std::cout << "if expr[" << ifb->lineNo <<"]: " << ifb->getExpr()->toString() << std::endl;
for( auto expr : ifb->childrenNodes ) {
if ( expr->is<BinExpression>() ) {
auto bin = expr->as<BinExpression>();
if (bin->getOp()->toString() == "and") {
printAndClauses(bin);
/*
std::cout << bin->getLeft()->toString()
<< std::endl
<< bin->getRight()->toString()
<< std::endl;
*/
}
}
}
std::cout << std::endl;
} else if( p->is<Comment>() ) {
std::cout << p->toString() << std::endl;
}
}
return 0;
}