str_plus.cpp

  name="google_ads_frame" marginwidth="0" marginheight="0" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-5572165936844014&dt=1194442938015&lmt=1194190197&format=336x280_as&output=html&correlator=1194442937843&url=file%3A%2F%2F%2FC%3A%2FDocuments%2520and%2520Settings%2Flhh1%2F%E6%A1%8C%E9%9D%A2%2FCLanguage.htm&color_bg=FFFFFF&color_text=000000&color_link=000000&color_url=FFFFFF&color_border=FFFFFF&ad_type=text&ga_vid=583001034.1194442938&ga_sid=1194442938&ga_hid=1942779085&flash=9&u_h=768&u_w=1024&u_ah=740&u_aw=1024&u_cd=32&u_tz=480&u_java=true" frameborder="0" width="336" scrolling="no" height="280" allowtransparency="allowtransparency"> #include <iostream.h>
#include <iomanip.h>
#include <string.h>

class String {
  public:
    char *operator +(char *append_str)
      { return(strcat(buffer, append_str)); };
  
    String(char *string)
      {
  strcpy(buffer, string);
        length = strlen(buffer);
 }

    void show_string(void) { cout << buffer; };
 
    void strapd(char *source) { strcat(buffer, source); };

  private:
    char buffer[256];
    int length;
};


void main(void)
 {
   String title("Jamsa's C/C++ ");
   title = title + "Programmer's Bible/n";
   title.show_string();

 
   String book2("Rescued by C++");
   book2.strapd(", Third Edition ");
   book2.show_string();
 }

 

c++: fatal error: Killed signal terminated program cc1plus compilation terminated. gmake[2]: *** [CMakeFiles/_tenseal_cpp.dir/build.make:225: CMakeFiles/_tenseal_cpp.dir/tenseal/cpp/tensors/bfvtensor.cpp.o] Error 1 gmake[2]: *** Waiting for unfinished jobs.... c++: fatal error: Killed signal terminated program cc1plus compilation terminated. gmake[2]: *** [CMakeFiles/_sealapi_cpp.dir/build.make:160: CMakeFiles/_sealapi_cpp.dir/tenseal/sealapi/sealapi_context.cpp.o] Error 1 gmake[2]: *** Waiting for unfinished jobs.... c++: fatal error: Killed signal terminated program cc1plus compilation terminated. gmake[2]: *** [CMakeFiles/_tenseal_cpp.dir/build.make:82: CMakeFiles/_tenseal_cpp.dir/tenseal/sealapi/sealapi.cpp.o] Error 1 c++: fatal error: Killed signal terminated program cc1plus compilation terminated. gmake[2]: *** [CMakeFiles/tenseal.dir/build.make:108: CMakeFiles/tenseal.dir/tenseal/cpp/tensors/bfvvector.cpp.o] Error 1 gmake[2]: *** Waiting for unfinished jobs.... c++: fatal error: Killed signal terminated program cc1plus compilation terminated. gmake[2]: *** [CMakeFiles/_tenseal_cpp.dir/build.make:108: CMakeFiles/_tenseal_cpp.dir/tenseal/sealapi/sealapi_encrypt.cpp.o] Error 1 c++: fatal error: Killed signal terminated program cc1plus compilation terminated. gmake[2]: *** [CMakeFiles/_tenseal_cpp.dir/build.make:212: CMakeFiles/_tenseal_cpp.dir/tenseal/cpp/tensors/bfvvector.cpp.o] Error 1 c++: fatal error: Killed signal terminated program cc1plus compilation terminated. gmake[2]: *** [CMakeFiles/_tenseal_cpp.dir/build.make:277: CMakeFiles/_tenseal_cpp.dir/tenseal/binding.cpp.o] Error 1 c++: fatal error: Killed signal terminated program cc1plus compilation terminated. gmake[2]: *** [CMakeFiles/_sealapi_cpp.dir/build.make:173: CMakeFiles/_sealapi_cpp.dir/tenseal/sealapi/sealapi_util_namespace.cpp.o] Error 1 gmake[1]: *** [CMakeFiles/Makefile2:452: CMakeFiles/_sealapi_cpp.dir/all] Error 2 gmake[1]: *** Waiting for unfinished jobs.... gmake[1]: *** [CMakeFiles/Makefile2:425: CMakeFiles/tenseal.dir/all] Error 2 gmake[1]: *** [CMakeFiles/Makefile2:397: CMakeFiles/_tenseal_cpp.dir/all] Error 2 gmake: *** [Makefile:149: all] Error 2 Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 389, in <module> main() File "/usr/local/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 373, in main json_out["return_val"] = hook(**hook_input["kwargs"]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 280, in build_wheel return _build_backend().build_wheel( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/pip-build-env-rh2o3tra/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 435, in build_wheel return _build(['bdist_wheel', '--dist-info-dir', str(metadata_directory)]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/pip-build-env-rh2o3tra/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 423, in _build return self._build_with_temp_dir( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/pip-build-env-rh2o3tra/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 404, in _build_with_temp_dir self.run_setup() File "/tmp/pip-build-env-rh2o3tra/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 512, in run_setup super().run_setup(setup_script=setup_script) File "/tmp/pip-build-env-rh2o3tra/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 317, in run_setup exec(code, locals()) File "<string>", line 81, in <module> File "/tmp/pip-build-env-rh2o3tra/overlay/lib/python3.11/site-packages/setuptools/__init__.py", line 115, in setup return distutils.core.setup(**attrs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/pip-build-env-rh2o3tra/overlay/lib/python3.11/site-packages/setuptools/_distutils/core.py", line 186, in setup return run_commands(dist) ^^^^^^^^^^^^^^^^^^ File "/tmp/pip-build-env-rh2o3tra/overlay/lib/python3.11/site-packages/setuptools/_distutils/core.py", line 202, in run_commands dist.run_commands() File "/tmp/pip-build-env-rh2o3tra/overlay/lib/python3.11/site-packages/setuptools/_distutils/dist.py", line 1002, in run_commands self.run_command(cmd) File "/tmp/pip-build-env-rh2o3tra/overlay/lib/python3.11/site-packages/setuptools/dist.py", line 1102, in run_command super().run_command(command) File "/tmp/pip-build-env-rh2o3tra/overlay/lib/python3.11/site-packages/setuptools/_distutils/dist.py", line 1021, in run_command cmd_obj.run() File "/tmp/pip-build-env-rh2o3tra/overlay/lib/python3.11/site-packages/setuptools/command/bdist_wheel.py", line 370, in run self.run_command("build") File "/tmp/pip-build-env-rh2o3tra/overlay/lib/python3.11/site-packages/setuptools/_distutils/cmd.py", line 357, in run_command self.distribution.run_command(command) File "/tmp/pip-build-env-rh2o3tra/overlay/lib/python3.11/site-packages/setuptools/dist.py", line 1102, in run_command super().run_command(command) File "/tmp/pip-build-env-rh2o3tra/overlay/lib/python3.11/site-packages/setuptools/_distutils/dist.py", line 1021, in run_command cmd_obj.run() File "/tmp/pip-build-env-rh2o3tra/overlay/lib/python3.11/site-packages/setuptools/_distutils/command/build.py", line 135, in run self.run_command(cmd_name) File "/tmp/pip-build-env-rh2o3tra/overlay/lib/python3.11/site-packages/setuptools/_distutils/cmd.py", line 357, in run_command self.distribution.run_command(command) File "/tmp/pip-build-env-rh2o3tra/overlay/lib/python3.11/site-packages/setuptools/dist.py", line 1102, in run_command super().run_command(command) File "/tmp/pip-build-env-rh2o3tra/overlay/lib/python3.11/site-packages/setuptools/_distutils/dist.py", line 1021, in run_command cmd_obj.run() File "<string>", line 46, in run File "<string>", line 78, in build_extension File "/usr/local/lib/python3.11/subprocess.py", line 413, in check_call raise CalledProcessError(retcode, cmd) subprocess.CalledProcessError: Command '['cmake', '--build', '.', '--config', 'Release', '--', '-j']' returned non-zero exit status 2. [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for tenseal error: failed-wheel-build-for-install × Failed to build installable wheels for some pyproject.toml based projects ╰─> tenseal
08-06
#include <bits/stdc++.h> #include <unordered_map> #include <stdexcept> using namespace std; /*---------------------------词法分析部分---------------------------*/ unordered_map<string, string> key_word_map = { {"const", "CONSTTK"}, {"int", "INTTK"}, {"char", "CHARTK"}, {"void", "VOIDTK"}, {"main", "MAINTK"}, {"if", "IFTK"}, {"else", "ELSETK"}, {"while", "WHILETK"}, {"for", "FORTK"}, {"do", "DOTK"}, {"return", "RETURNTK"}, {"printf", "PRINTFTK"}, {"scanf", "SCANFTK"} }; unordered_map<string, string> operator_map = { {"+", "PLUS"}, {"-", "MINU"}, {"*", "MULT"}, {"/", "DIV"}, {"=", "ASSIGN"}, {"==", "EQL"}, {"!=", "NEQ"}, {"<", "LSS"}, {"<=", "LEQ"}, {">", "GRE"}, {">=", "GEQ"}, {"(", "LPARENT"}, {")", "RPARENT"}, {"[", "LBRACK"}, {"]", "RBRACK"}, {"{", "LBRACE"}, {"}", "RBRACE"}, {";", "SEMICN"}, {",", "COMMA"} }; bool isKeyWord(const string& token) { return key_word_map.find(token) != key_word_map.end(); } string getOperator(ifstream& fin, char c) { string op(1, c); if (c == '=' || c == '!' || c == '<' || c == '>') { char next = fin.peek(); if (next == '=') { op += next; fin.get(); } } return op; } void lexAnalyze(const string& input_file, const string& lex_temp_file) { ifstream fin(input_file); ofstream fout(lex_temp_file); if (!fin.is_open()) { cerr << "无法打开输入文件: " << input_file << endl; exit(1); } if (!fout.is_open()) { cerr << "无法创建临时词法文件: " << lex_temp_file << endl; exit(1); } char c; while (fin.get(c)) { if (isspace(c)) continue; if (isalpha(c) || c == '_') { string token; token += c; while (fin.get(c) && (isalnum(c) || c == '_')) token += c; fin.unget(); if (isKeyWord(token)) fout << key_word_map[token] << " " << token << endl; else fout << "IDENFR " << token << endl; } else if (isdigit(c)) { string num; num += c; while (fin.get(c) && isdigit(c)) num += c; fin.unget(); fout << "INTCON " << num << endl; } else if (c == '\'') { char ch; fin.get(ch); fout << "CHARCON " << ch << endl; fin.get(c); // 读取闭合单引号 } else if (c == '\"') { string str; char ch; while (fin.get(ch) && ch != '\"') str += ch; fout << "STRCON " << str << endl; } else { string op = getOperator(fin, c); if (operator_map.count(op)) fout << operator_map[op] << " " << op << endl; else cerr << "警告: 未知符号 '" << c << "'" << endl; } } fin.close(); fout.close(); } /*---------------------------语法分析部分---------------------------*/ struct Token { string type; string value; }; Token current_token; ifstream lex_input; ofstream syntax_output; long long prev_pos = -1; void save_pos() { prev_pos = lex_input.tellg(); } void restore_pos() { if (prev_pos != -1) { lex_input.seekg(prev_pos); prev_pos = -1; } } void next_token() { save_pos(); if (lex_input >> current_token.type >> current_token.value) { syntax_output << current_token.type << " " << current_token.value << endl; } else { current_token.type = ""; current_token.value = ""; } } Token peek_token() { Token temp = current_token; long long pos = lex_input.tellg(); Token next; if (lex_input >> next.type >> next.value) { lex_input.seekg(pos); current_token = temp; return next; } else { lex_input.clear(); lex_input.seekg(pos); current_token = temp; return Token{"", ""}; } } void match(const string& expected) { if (current_token.type != expected) { throw runtime_error("语法错误: 预期 '" + expected + "', 实际 '" + current_token.type + "' (值: " + current_token.value + ")"); } next_token(); } /* 递归子程序声明 */ void parse_program(); void parse_const_decl(); void parse_const_def(); void parse_integer(); void parse_unsigned_integer(); void parse_var_decl(); void parse_var_def(); void parse_type_identifier(); void parse_func_def_with_return(); void parse_func_def_without_return(); void parse_decl_head(); void parse_param_list(); void parse_main_func(); void parse_compound_stmt(); void parse_stmt_list(); void parse_stmt(); void parse_assign_stmt(); void parse_condition_stmt(); void parse_loop_stmt(); void parse_return_stmt(); void parse_read_stmt(); void parse_write_stmt(); void parse_expr_stmt(); void parse_empty_stmt(); void parse_expr(); void parse_term(); void parse_factor(); void parse_arg_list(); void parse_string(); void parse_condition(); void parse_step(); void parse_add_op(); void parse_mul_op(); void parse_rel_op(); /* 程序入口 */ void parse_program() { // 解析常量说明 if (current_token.type == "CONSTTK") { parse_const_decl(); } // 解析变量说明 if (current_token.type == "INTTK" || current_token.type == "CHARTK") { parse_var_decl(); } // 解析函数定义 while (true) { Token next = peek_token(); // 判断是否为函数定义(类型后接标识符和左括号) if ((current_token.type == "INTTK" || current_token.type == "CHARTK") && next.type == "IDENFR" && peek_token().type == "LPARENT") { parse_func_def_with_return(); } else if (current_token.type == "VOIDTK" && next.type == "IDENFR" && peek_token().type == "LPARENT") { parse_func_def_without_return(); } else { break; } } // 解析主函数 parse_main_func(); syntax_output << "<程序>" << endl; } /* 常量说明 */ void parse_const_decl() { while (current_token.type == "CONSTTK") { match("CONSTTK"); parse_const_def(); match("SEMICN"); } syntax_output << "<常量说明>" << endl; } /* 常量定义 */ void parse_const_def() { if (current_token.type == "INTTK") { match("INTTK"); match("IDENFR"); match("ASSIGN"); parse_integer(); while (current_token.type == "COMMA") { match("COMMA"); match("IDENFR"); match("ASSIGN"); parse_integer(); } } else if (current_token.type == "CHARTK") { match("CHARTK"); match("IDENFR"); match("ASSIGN"); match("CHARCON"); while (current_token.type == "COMMA") { match("COMMA"); match("IDENFR"); match("ASSIGN"); match("CHARCON"); } } syntax_output << "<常量定义>" << endl; } /* 整数 */ void parse_integer() { if (current_token.type == "PLUS" || current_token.type == "MINU") { match(current_token.type); } parse_unsigned_integer(); syntax_output << "<整数>" << endl; } /* 无符号整数 */ void parse_unsigned_integer() { match("INTCON"); syntax_output << "<无符号整数>" << endl; } /* 变量说明 */ void parse_var_decl() { while (true) { // 预读下一个token,判断是变量定义还是函数定义 Token next = peek_token(); if ((current_token.type == "INTTK" || current_token.type == "CHARTK") && next.type == "IDENFR") { // 再预读一个token,判断标识符后是分号/逗号还是左括号 Token next_next = peek_token(); if (next_next.type == "SEMICN" || next_next.type == "COMMA") { parse_var_def(); match("SEMICN"); } else { break; // 是函数定义,退出变量说明解析 } } else { break; } } syntax_output << "<变量说明>" << endl; } /* 变量定义 */ void parse_var_def() { parse_type_identifier(); match("IDENFR"); while (current_token.type == "COMMA") { match("COMMA"); match("IDENFR"); } syntax_output << "<变量定义>" << endl; } /* 类型标识符 */ void parse_type_identifier() { if (current_token.type == "INTTK") { match("INTTK"); } else if (current_token.type == "CHARTK") { match("CHARTK"); } else { throw runtime_error("预期类型标识符,实际为: " + current_token.type); } } /* 有返回值函数定义 */ void parse_func_def_with_return() { parse_decl_head(); match("LPARENT"); parse_param_list(); match("RPARENT"); match("LBRACE"); parse_compound_stmt(); match("RBRACE"); syntax_output << "<有返回值函数定义>" << endl; } /* 声明头部 */ void parse_decl_head() { parse_type_identifier(); match("IDENFR"); syntax_output << "<声明头部>" << endl; } /* 参数表 */ void parse_param_list() { if (current_token.type == "INTTK" || current_token.type == "CHARTK") { parse_type_identifier(); match("IDENFR"); while (current_token.type == "COMMA") { match("COMMA"); parse_type_identifier(); match("IDENFR"); } } syntax_output << "<参数表>" << endl; } /* 主函数 */ void parse_main_func() { match("VOIDTK"); match("MAINTK"); match("LPARENT"); match("RPARENT"); match("LBRACE"); parse_compound_stmt(); match("RBRACE"); syntax_output << "<主函数>" << endl; } /* 复合语句 */ void parse_compound_stmt() { if (current_token.type == "CONSTTK") { parse_const_decl(); } if (current_token.type == "INTTK" || current_token.type == "CHARTK") { parse_var_decl(); } parse_stmt_list(); syntax_output << "<复合语句>" << endl; } /* 语句列 */ void parse_stmt_list() { while (current_token.type != "RBRACE" && !current_token.type.empty()) { parse_stmt(); } syntax_output << "<语句列>" << endl; } /* 语句 */ void parse_stmt() { if (current_token.type == "IFTK") { parse_condition_stmt(); } else if (current_token.type == "WHILETK" || current_token.type == "FORTK" || current_token.type == "DOTK") { parse_loop_stmt(); } else if (current_token.type == "LBRACE") { match("LBRACE"); parse_stmt_list(); match("RBRACE"); } else if (current_token.type == "IDENFR") { Token next = peek_token(); if (next.type == "LPARENT") { parse_expr_stmt(); } else { parse_assign_stmt(); } } else if (current_token.type == "SCANFTK") { parse_read_stmt(); } else if (current_token.type == "PRINTFTK") { parse_write_stmt(); } else if (current_token.type == "RETURNTK") { parse_return_stmt(); } else if (current_token.type == "SEMICN") { parse_empty_stmt(); } else { throw runtime_error("未知语句类型: " + current_token.type); } syntax_output << "<语句>" << endl; } /* 赋值语句 */ void parse_assign_stmt() { match("IDENFR"); if (current_token.type == "LBRACK") { match("LBRACK"); parse_expr(); match("RBRACK"); } match("ASSIGN"); parse_expr(); match("SEMICN"); syntax_output << "<赋值语句>" << endl; } /* 条件语句 */ void parse_condition_stmt() { match("IFTK"); match("LPARENT"); parse_condition(); match("RPARENT"); parse_stmt(); if (current_token.type == "ELSETK") { match("ELSETK"); parse_stmt(); } syntax_output << "<条件语句>" << endl; } /* 循环语句 */ void parse_loop_stmt() { if (current_token.type == "WHILETK") { match("WHILETK"); match("LPARENT"); parse_condition(); match("RPARENT"); parse_stmt(); } else if (current_token.type == "DOTK") { match("DOTK"); parse_stmt(); match("WHILETK"); match("LPARENT"); parse_condition(); match("RPARENT"); match("SEMICN"); } else if (current_token.type == "FORTK") { match("FORTK"); match("LPARENT"); match("IDENFR"); match("ASSIGN"); parse_expr(); match("SEMICN"); parse_condition(); match("SEMICN"); match("IDENFR"); match("ASSIGN"); match("IDENFR"); if (current_token.type == "PLUS" || current_token.type == "MINU") { match(current_token.type); parse_step(); } match("RPARENT"); parse_stmt(); } syntax_output << "<循环语句>" << endl; } /* 返回语句 */ void parse_return_stmt() { match("RETURNTK"); if (current_token.type == "LPARENT") { match("LPARENT"); parse_expr(); match("RPARENT"); } match("SEMICN"); syntax_output << "<返回语句>" << endl; } /* 读语句 */ void parse_read_stmt() { match("SCANFTK"); match("LPARENT"); match("IDENFR"); while (current_token.type == "COMMA") { match("COMMA"); match("IDENFR"); } match("RPARENT"); match("SEMICN"); syntax_output << "<读语句>" << endl; } /* 写语句 */ void parse_write_stmt() { match("PRINTFTK"); match("LPARENT"); if (current_token.type == "STRCON") { parse_string(); if (current_token.type == "COMMA") { match("COMMA"); parse_expr(); } } else { parse_expr(); } match("RPARENT"); match("SEMICN"); syntax_output << "<写语句>" << endl; } /* 表达式语句(函数调用) */ void parse_expr_stmt() { match("IDENFR"); match("LPARENT"); parse_arg_list(); match("RPARENT"); match("SEMICN"); syntax_output << "<有返回值函数调用语句>" << endl; } /* 空语句 */ void parse_empty_stmt() { match("SEMICN"); syntax_output << "<空>" << endl; } /* 表达式 */ void parse_expr() { if (current_token.type == "PLUS" || current_token.type == "MINU") { match(current_token.type); } parse_term(); while (current_token.type == "PLUS" || current_token.type == "MINU") { parse_add_op(); parse_term(); } syntax_output << "<表达式>" << endl; } /* 项 */ void parse_term() { parse_factor(); while (current_token.type == "MULT" || current_token.type == "DIV") { parse_mul_op(); parse_factor(); } syntax_output << "<项>" << endl; } /* 因子 */ void parse_factor() { if (current_token.type == "IDENFR") { match("IDENFR"); if (current_token.type == "LBRACK") { match("LBRACK"); parse_expr(); match("RBRACK"); } else if (current_token.type == "LPARENT") { match("LPARENT"); parse_arg_list(); match("RPARENT"); } } else if (current_token.type == "LPARENT") { match("LPARENT"); parse_expr(); match("RPARENT"); } else if (current_token.type == "INTCON") { parse_integer(); } else if (current_token.type == "CHARCON") { match("CHARCON"); } else { throw runtime_error("无效的因子类型: " + current_token.type); } syntax_output << "<因子>" << endl; } /* 值参数表 */ void parse_arg_list() { if (current_token.type != "RPARENT") { parse_expr(); while (current_token.type == "COMMA") { match("COMMA"); parse_expr(); } } syntax_output << "<值参数表>" << endl; } /* 字符串 */ void parse_string() { match("STRCON"); syntax_output << "<字符串>" << endl; } /* 条件 */ void parse_condition() { parse_expr(); if (current_token.type == "EQL" || current_token.type == "NEQ" || current_token.type == "LSS" || current_token.type == "LEQ" || current_token.type == "GRE" || current_token.type == "GEQ") { parse_rel_op(); parse_expr(); } } /* 步长 */ void parse_step() { parse_unsigned_integer(); } /* 加法运算符 */ void parse_add_op() { if (current_token.type == "PLUS" || current_token.type == "MINU") { match(current_token.type); } else { throw runtime_error("预期加法运算符,实际为: " + current_token.type); } syntax_output << "<加法运算符>" << endl; } /* 乘法运算符 */ void parse_mul_op() { if (current_token.type == "MULT" || current_token.type == "DIV") { match(current_token.type); } else { throw runtime_error("预期乘法运算符,实际为: " + current_token.type); } syntax_output << "<乘法运算符>" << endl; } /* 关系运算符 */ void parse_rel_op() { if (current_token.type == "EQL" || current_token.type == "NEQ" || current_token.type == "LSS" || current_token.type == "LEQ" || current_token.type == "GRE" || current_token.type == "GEQ") { match(current_token.type); } else { throw runtime_error("预期关系运算符,实际为: " + current_token.type); } syntax_output << "<关系运算符>" << endl; } /* 无返回值函数定义 */ void parse_func_def_without_return() { match("VOIDTK"); match("IDENFR"); match("LPARENT"); parse_param_list(); match("RPARENT"); match("LBRACE"); parse_compound_stmt(); match("RBRACE"); syntax_output << "<无返回值函数定义>" << endl; } /*---------------------------主函数---------------------------*/ int main() { const string input_file = "testfile.txt"; const string output_file = "output.txt"; const string lex_temp_file = "lex_temp.txt"; lexAnalyze(input_file, lex_temp_file); lex_input.open(lex_temp_file); syntax_output.open(output_file, ios::binary); if (!lex_input.is_open() || !syntax_output.is_open()) { cerr << "文件打开失败" << endl; return 1; } try { next_token(); parse_program(); cout << "分析完成,结果已写入 " << output_file << endl; } catch (const exception& e) { cerr << "\n分析错误: " << e.what() << endl; return 1; } lex_input.close(); syntax_output.close(); remove(lex_temp_file.c_str()); return 0; }对该代码进行修改实现目的,给出完整代码
11-05
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值