-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
73 lines (73 loc) · 1.81 KB
/
main.cpp
File metadata and controls
73 lines (73 loc) · 1.81 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
//These are the libraries I included
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
//something to shorten the code significantly
using namespace std;
//variables
vector<string> variables;
//finds where an element is in a vector
int maybe(vector<string> i, string test){
for(int c=0; c<i.size(); c++){
if(i[c]==test){
return c;
}
}
return -1;
}
int main() {
string i;
cout << "Which file do you want to open? ";
cin>>i;
if(i.find(".shrek")==i.length()-6){
ifstream test;
test.open(i);
string g;
while(getline(test, g)){
//print statement
if(g.find("shreksays(")==0 && g.find(")")==g.length()-1){
//tests if the variable is real
string tempvar="";
//this adds to the temporary variable so that it contains a variable name
for(int o=10; o<g.length()-1; o++){
tempvar+=g[o];
}
//references the variable name and prints the one after
if(maybe(variables, tempvar) > 0-1 && maybe(variables, tempvar)%2==0){
cout<<variables[maybe(variables, tempvar)+1];
}else{
//error
cout<<"Get out of my swamp!\n";
break;
}
cout<<"\n";
}else if(g.find("ogres are like ")==0 && g.find(" they have ")){
//Variables
string varname="";
string varcontent="";
//gets the variable name
for(int o=15; o<g.find(" they have "); o++){
varname+=g[o];
};
//pushes it to the vector (like a dictionary)
variables.push_back(varname);
//this is the variable content
for(int o=26+varname.length(); o<g.length(); o++){
varcontent+=g[o];
}
variables.push_back(varcontent);
}else if(g.find("shrekis")==0){
//comment syntax
continue;
}else if(g==""){
//just make sure that blankspace is ignored
continue;
}else{
//error
cout<<"That's not very shreksy\n";
break;
}
}
}
}