int main(int argc, char **argv) { atexit(FINISH); if (argc != 2) ERROR("Source file not specified."); SourceFile = argv[1]; DebugStream.open("compile.txt", ios::out | ios::trunc); DebugStream << "\n### SPOKOL(TM) Compiler ###\n\n"; DebugStream << "Copyleft 2002 by Omega Red\n[[email protected]]\n"; DebugStream << "[Built " __DATE__ " " __TIME__ "]\n\n"; DebugStream << "Source file: " << SourceFile << "\n\n"; lex_analyze(); if (ErrorOccured) ERROR("Lexical analysis failed."); syn_analyze(); if (ErrorOccured) ERROR("Syntax analysis failed."); sem_analyze(); if (ErrorOccured) ERROR("Semantic analysis failed."); gen_start(); if (ErrorOccured) ERROR("Code generation failed."); DebugStream.close(); return 0; }
void matchOptions( std::vector<std::string> vec_options, std::vector<struct Option_Info>& options, std::vector<std::string> buf , vector<struct AnnotationRange> range ,std::map< std::string, double > entropy_dict){ for(int j = 0; j < buf.size(); j++){ for(int i = 0 ; i < vec_options.size(); i++){ int column = buf[j].find( string("\""+vec_options[i]+"\"")); if( column != std::string::npos){ //在配置名外加引号匹配确定长度,减少匹配到多余字符的情况(如AllowOverride匹配到AllowOverrideList) Option_Info op_info; op_info.option_name = vec_options[i]; op_info.line_num = j + 1; op_info.column = column+1; //多加了一个“ \" ”,所以column位置需要+1向后移一位 getVocabulary( vec_options[i].c_str(), op_info.dict); //分词并记录相关信息 struct Word word[MAX_WORD_NUM]; int word_cnt = lex_analyze(buf, j, word, range); // printf("word_cnt = %d\n", word_cnt); for(int j = 0 ; j < word_cnt ; j++){ if(string(word[j].word_name) == vec_options[i] && word[j].line_num == op_info.line_num && word[j].column == op_info.column) word[j].isOptionSelf = true; else word[j].isOptionSelf = false; } // printf("%s\n", vec_options[i].c_str()); // for(int j = 0 ; j < word_cnt ; j++){ // printf("%d %s %d %d %d\n", j , word[j].word_name, word[j].line_num , word[j].column, word[j].isOptionSelf); // } //对单词进行相关性计算 calcRelativity(op_info, word, word_cnt, entropy_dict); //记录有用信息 recordVariableInfo( op_info , word , j , word_cnt); options.push_back(op_info); } } } return ; }