-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
57 lines (48 loc) · 1.64 KB
/
Main.cpp
File metadata and controls
57 lines (48 loc) · 1.64 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
#include "Headers.hpp"
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <bitset>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
//g++ -std=c++17 -pedantic -g -O3 -I Main.cpp
//g++ -std=c++17 -g -O3 -I Main.cpp
/*int main()
{d
cout<< "What would you like to see." <<endl;
cout << "Option 1: Evaluate formula and get final truth values" << endl;
cout << "Option 2: Given a formula will give Tautology, Contradiction, Contingency." << endl;
cout << "Option 3: Check if two formulas are equivalent" << endl;
cout << "Option 3: Given an argument, will print whether the argument is valid or invalid." << endl;
return 0;
}*/
int main()
{
cout << "The logical connectives this program uses are, v (disjunction), & (conjunction), -> (conditional), <-> (biconditonal) " << endl;
cout << "Compound propositions require parantheses." << endl;
cout << "Here are a few examples of valid logical expressions:"<<endl;
cout << "p&q "<<endl<< "~(p->q)"<<endl<< "((p&q)vs)->~(p<->x)"<<endl;
cout << "Any letters can be used as variables except for v, which is the OR operator." <<endl<<endl;
cout << "Enter logical expression:" << endl;
cout<< "Enter 0 to break the loop."<<endl;
while(true){
string sentence;
cin >> sentence;
if (sentence == "0"){exit(0);}
Parser p;
p.start(sentence);
if(p.well_formed == false){exit(0);}
Node root {p.token_string};
Evaluator e;
e.add_to_tree(&root);
e.evaluate(p.l_count);
int n = root.value.size();
for(int i=n-1;i>=0;i--)
{
cout<<root.value[i] <<endl;
}
}
return 0;
}