问题描述
我必须制作一个计算器,并且需要为此使用解析器。 我的解析器输入是 std::istream* input ,我需要将我的 QString 从我的计算器应用程序转换为我的解析器的输入,以便它进行数学运算并返回解决方案。 你知道如何转换吗?感谢您的回答! :) 如果您想要解析器的完整代码,请在此处 -> https://www.stroustrup.com/dc_except.c
这是我通过控制台输入的主要内容
#include <strstream.h>
int main(int argc,char* argv[])
{
using namespace Driver;
switch (argc) {
case 1: // read from standard input
input = &cin;
break;
case 2: // read argument string
input = new istrstream(argv[1],strlen(argv[1]));
break;
default:
cerr << "too many arguments\n";
return 1;
}
// insert pre-defined names:
Symbol_table::table["pi"] = 3.1415926535897932385;
Symbol_table::table["e"] = 2.7182818284590452354;
while (*input) {
cout<<"new expression:\n";
try {
Lexer::get_token();
if (Lexer::curr_tok == Lexer::END) break;
if (Lexer::curr_tok == Lexer::PRINT) continue;
cout << Parser::expr(false) << '\n';
}
catch(Error::Zero_divide) {
cerr << "attempt to divide by zero\n";
skip();
}
catch(Error::Syntax_error e) {
cerr << "Syntax error:" << e.p << "\n";
skip();
}
}
if (input != &std::cin) delete input;
return no_of_errors;
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)