Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Lex cpp
//g++ 5.4.0 #include <iostream> #include <fstream> #include <string> using namespace std; bool singleQuote(ofstream fout, ofstream ofs, string text, int ¤t=0){ int i = current; int j = 0; string temp; if(text[i] == 39){ temp[j] = text[i]; //print to file i++; current = i; return true; } return false; } bool doubleQuote(ofstream fout, ofstream ofs, string text, int ¤t=0){ int i = current; int j = 0; string temp; if(text[i] == 34){ temp[j] = text[i]; //print to file i++; current = i; return true; } return false; } bool isKeyword(ofstream fout, ofstream ofs, string text, int ¤t=0){ } bool isDatatype(ofstream fout, ofstream ofs, string text, int ¤t=0){ } bool isIdentifier(ofstream fout, ofstream ofs, string text, int ¤t=0){ int i = current; int j = 0; string temp; while(text[i] == 32) i++;//skip whitespace if((text[i] > 64 && text[i++] < 91) || (text[i] > 96 && text[i] < 123)){ temp[j++] = text[i++]; //inc after assignment while(text[i] != '\0') { if((text[i] > 64 && text[i] < 91) || (text[i] > 96 && text[i] < 123) || (text[i] > 47 && text[i] < 58)) { temp[j++] = text[i]; //inc after assignment } i++; } //print to files current = i;//set counter to next return true; } //maybe print error here? (Maybe better to print in the calling function switch statements) return false; } bool isInt(ofstream fout, ofstream ofs, string text, int ¤t=0){ int i = current; int j = 0; string temp; while(text[i] == 32) i++;//skip whitespace if(text[i] > 47 && text[i] < 58){ temp[j++] = text[i++]; while(text[i] != '\0') { if(text[i] > 47 && text[i] < 58) { temp[j++] = text[i]; //inc after assignment } i++; } //print to files current = i;//set counter to next return true; } //maybe print error return false; } bool isChar(ofstream fout, ofstream ofs, string text, int ¤t=0){ int i = current; int j = 0; string temp; while(text[i] == 32) i++;//skip whitespace bool val = singleQuote(fout, ofs, text, current); if(text[i] > -1 && text[i] < 256){ temp[j++] = text[i++]; //print to files } else val = false; current = i; if (val) val = singleQuote(fout, ofs, text, current); //maybe print error return val; } bool isString(ofstream fout, ofstream ofs, string text, int ¤t=0){ int i = current; int j = 0; string temp; while(text[i] == 32) i++;//skip whitespace bool val = doubleQuote(fout, ofs, text, current); //print token while(text[i] != 34){ temp[j++] = text[i++]; //print to files } current = i; if (val) val = doubleQuote(fout, ofs, text, current); //maybe print error return val; } bool isAssign(ofstream fout, ofstream ofs, string text, int ¤t=0){ int i = current; int j = 0; string temp; while(text[i] == 32) i++;//skip whitespace if(text[i] == '<'){ temp[j++] = text[i++]; if(text[i] == '-'){ temp[j++] = text[i++]; //print to file (deal with null char too) current = i; return true; } } return false; } bool isRelational(ofstream fout, ofstream ofs, string text, int ¤t=0); bool opEndline(ofstream fout, ofstream ofs, string text, int ¤t=0); bool opLib(ofstream fout, ofstream ofs, string text, int ¤t=0); bool funcDeclaration(ofstream fout, ofstream ofs, string text, int ¤t=0); bool programBody(ofstream fout, ofstream ofs, string text, int ¤t = 0){ bool isCorrect = true; int x = 1; while(isCorrect){ //read next line here switch(x){ case 1: isCorrect = opLib(text, current); x++; if (!isCorrect) x = 0; break; case 2: isCorrect = funcDeclaration(text, current); x++; if (!isCorrect) x = 0; break; case 3: isCorrect = opEndline(text, current); x = 1; if (!isCorrect) x = 0; break; case 0: opLib(); isCorrect = false; } opLib(); } opLib(); } int main() { //read from console? string inputName; cin >> inputName; bool check; string x; ifstream fin(inputName); ofstream fout, ofs; if (fin.is_open()) { fout.open("words.txt", ios::app); ofs.open("symboltable.txt", ios::app); while(getline(fin, x)) { //dowhatever check = programBody(fout, ofs, x) } fin.close(); } fout.close(); ofs.close(); }
run
|
edit
|
history
|
help
0
Updated Linked Lists - 5/10/2017 V4.0
Kolokwium_2011_z7
Find Triplets or Duplets that the sum is multiplie of three
Meeting_Leandro
BinTree
Beadandó
ONP is working!
code
Vec+Mem+Adv_11
шаблонизированное наследование