int main( int argc, char* argv[] ) { setlocale(0, ""); // setlocale(LC_CTYPE, ""); // Файлы с которыми мы будем работать. ifstream input_file; ofstream output_file; /** * Собираем переданные нам параметры и открываем файлы для работы. * Если что-то не удалось сделать, то функция выведет ошибку, а мы закончим выполнение. */ if ( !readConsoleParams( argc, argv, input_file, output_file ) ) { return 0; } // Данные для лексера пока тут. Нужно будет куда-нибудь засунуть для удобного изменения string res_words[] = { "reserve" }; string structures[] = { "Def:", "Ex:", "Thm:", "Proof:", "Note:", "Comment:", "Task:", "Table:", "#", "##", "###", "####", "######", "+", "---", "*", "**" }; string deviders[] = { " ", "\n", "\t"}; // "{", "}", // Запускаем лексический анализатор Lexer lex; lex.Init( res_words, 1, structures, 17, deviders, 3 ); string text; while ( !input_file.eof() ) { string buf; getline(input_file, buf); text+= buf + "\n"; } #ifdef __DBGOUTPUT__ MACRO_MESSAGE("\n---text:---\n" + text); #endif lex.lex(text); lex.save_tokens(); Compiler compiler; compiler.load_tokens( lex.get_tokens() ); compiler.compile(); output_file<<compiler; system("pause"); return 0; }
int main(int argc, char* argv[]) { std::istream* input = GetInput(argc, argv); std::string s; Lexer *pLexer = new Lexer(input); bool ret = pLexer->Init(); if(!ret) return 1; Parser parser(pLexer); ASTNode* root = parser.Parse(); if (root) { Value* value = root->eval(NULL); } else { std::cout << "root not found" << std::endl; } return 0; }
void main(void) { Lexer objLex; objLex.Init(); while (true) { string strInput = ""; while (strInput.empty()) { cout << "Input a filename or 'q' to quit: "; if (!getline(cin,strInput) || strInput == "q") { strInput = ""; break; } } // User typed "q" if it's empty (got here with "break") if (strInput.empty()) break; if (!objLex.Open(strInput.c_str())) { cout << "Error opening file: " << strInput << endl; continue; } Parser objParse(&objLex); bool created = false; try { if (objParse.Validate()) { created = true; Executer exe; exe.Execute(objParse.lstParseTree); //cout << exe.symTable << endl << endl; vector<DataValue>::iterator it; } else { cout << "Invalid source file, parse tree was not created." << endl; } } catch (Token objToken) { cout << "Lexer Error: " << objToken.dtValue << endl; } /*if (!created) { string strTemp; do { cout << "Would you like to view the partial parse-tree (y/n)? "; cin >> strTemp; cin.ignore(); cin.clear(); } while (strTemp!="y"&&strTemp!="Y"&&strTemp!="n"&&strTemp!="N"); if (tolower(strTemp[0]) == 'y') objParse.PrintTree(cout); }*/ objLex.Close(); cout << "End of file." << endl; } }