-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgjye++.cpp
137 lines (106 loc) · 3.72 KB
/
gjye++.cpp
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include <iostream>
#include <fstream>
#include <sstream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
//################ GLOBAL VARIABLES ################//
bool SHOW_DEBUGGING = false; // default no
/// ################################ ///
//################ IMPORT LIBRARIES ################//
#include "gjye++.h"
#include "blockWrappers.h"
#include "enviroWrap.h"
#include "objMethods.h"
#include "execTokenStruct.h"
/// ################################ ///
//################ MAIN DRIVER ################//
int main(int argc, char * argv[]) {
srand((unsigned) time(0)); // for random generation
// BUILD THE STANDARD LIBRARY //
EnviroWrap * eStack = new EnviroWrap();
FuncObj * tempObj = NULL;
// for each object in the STDL
eStack->methodStructure.pushStorage(); // add to the empty stack
std::string fullSTDLibrary[] = { "Add", "CharAt", "Exit", "IndexOf", "Join", "Local", "Lc", "LcFirst", "Length", "Print", "Random", "Remove", "Reverse", "Round", "Select", "Split", "ValueOf", "contains", "beginsWith", "isDefined", "Void", "0x0" };
for (int t = 0; fullSTDLibrary[t] != "0x0"; ++t) {
tempObj = exec::instantSTDL(&fullSTDLibrary[t]);
for (unsigned int i = 0; i < tempObj->returnType.size(); ++i) { // multiple types are combined in one, so loop through all possible combos (eg Add $ to $, Add % to $, etc)
eStack->methodStructure.addMethod(tempObj->returnType[i], "", tempObj->vocabulary, tempObj->paramType[i], tempObj->isOptional, tempObj->isSTDL, tempObj->isPostFixFunc);
}
delete tempObj;
}
//eStack->methodStructure.toString();
/* TEST
std::vector<std::string> tVecVocab;
tVecVocab.push_back("Add");
tVecVocab.push_back("in");
tVecVocab.push_back("after");
std::vector<std::string> tVecTypes;
tVecTypes.push_back("$");
tVecTypes.push_back("%");
tVecTypes.push_back("%");
eStack->methodStructure.findMatch(tVecVocab, tVecTypes);
*/
///
// parse flags
char * fileName = NULL;
for (int i = 1; i < argc; ++i) {
if (strlen(argv[i]) > 1 && argv[i][0] == '-') { // it's a flag
if (argv[i][1] != '-') {
switch (argv[i][1]) {
case 'h':
case '?':
std:: cout << "Usage: gjye++ [options] file ..." << "\nOptions: \n" <<
" -h\t\tDisplay this help information\n" <<
" -f <file>\tParse <file>\n" <<
" -v\t\tVersion\n" <<
" -d\t\tShow debugging output\n";
exit(0);
case 'd':
SHOW_DEBUGGING = true;
break;
case 'f':
++i;
fileName = argv[i];
break;
case 'v':
std::cout << "Gjye++ version Alpha class" <<std::endl;
exit(0);
}
}
} else fileName = argv[i]; // not a flag, so it should be the file name
}
///
if (fileName != NULL && strlen(fileName) > 0) {
std::ifstream inFile;
std::string fullUserInput = "", line = "";
ClassWrap * mainObject = NULL;
inFile.open(fileName, std::ios::in);
if (inFile.is_open()) {
if (SHOW_DEBUGGING) std::cout << "\nProcessing file " << fileName << "!" <<std::endl;
while ( !inFile.eof() ) {
getline(inFile,line);
fullUserInput += line;
}
mainObject = new ClassWrap("Main", fullUserInput, eStack);
mainObject->executeCode();
delete mainObject;
} else {std::cout << "Cannot open file " << fileName << "!" <<std::endl;exit(0);}
}
else { // command prompt (debugging)
std::cout << "cmd> ";
std::string fullUserInput = "";
ClassWrap * mainObject = NULL;
while (!getline(std::cin, fullUserInput).fail()) {
mainObject = new ClassWrap("Main", fullUserInput, eStack);
mainObject->executeCode();
delete mainObject;
std::cout << "\n\ncmd> ";
}
}
eStack->methodStructure.clearMemory();
delete eStack;
return 0;
}
/// ################################ ///