-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprincess.cpp
More file actions
70 lines (57 loc) · 1.44 KB
/
Copy pathprincess.cpp
File metadata and controls
70 lines (57 loc) · 1.44 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
#include <iostream>
#include <fstream>
#include "driver.h"
#include "LanguageContext.h"
#include "AST.h"
int main(int argc, char* argv[]){
PL::LanguageContext ctx;
PL::Driver driver(ctx);
bool readfile = false;
for(int ai = 1; ai < argc; ++ai)
{
if (argv[ai] == std::string ("-p")) {
driver.trace_parsing = true;
}
else if (argv[ai] == std::string ("-s")) {
driver.trace_scanning = true;
}
else
{
// read a file with expressions
std::fstream infile(argv[ai]);
if (!infile.good())
{
std::cerr << "Could not open file: " << argv[ai] << std::endl;
return 0;
}
bool result = driver.parse_stream(infile, argv[ai]);
readfile = true;
}
}
if (readfile) return 0;
std::cout << "Reading expressions from stdin" << std::endl;
std::string line;
while( std::cout << "input: " &&
std::getline(std::cin, line) &&
!line.empty() )
{
//ctx.clearExpressions();
bool result = driver.parse_string(line, "input");
if (result)
{
std::cout << "Valid input" << std::endl;
// for (unsigned int ei = 0; ei < calc.expressions.size(); ++ei)
// {
// std::cout << "tree:" << std::endl;
// //calc.expressions[ei]->print(std::cout);
// std::cout << "evaluated: "
// //<< calc.expressions[ei]->evaluate()
// << std::endl;
// }
}
else {
std::cout << "Invalid input" << std::endl;
}
}
return 0;
}