每次我运行此方法时,它都会返回我输出的错误消息。例如:用户输入:
display <table.txt> sortedby <ID>
这是我希望用户在调用显示函数时使用的正确语法。但是当用户类型使用正确的语法显示时,它会输出我指定的错误消息。
Syntax error: display <intable> sortedby <col_name>
总的来说,在这种方法中,我希望表格以漂亮的格式显示。但它不会超过 if 语句。我想知道是否有一些我忽略的东西可能会返回我的 error_message。
void display(Lexer lexer) {
Table table; // create a table from the created table class
vector<Token> tokvec = lexer.tokenize();
// expect [IDENT | STRING] sortedby IDENT
if (tokvec.size() != 4 ||
(tokvec[0].type != IDENT && tokvec[1].type != STRING) ||
tokvec[2].value != "sortedby" || tokvec[3].type != IDENT){
error_return("Syntax error: display <intable> sortedby <col_name>");
return;
}
string fn = tokvec[1].value; // name of the file
string col_name = tokvec[3].value;
table.set_input(fn);
table.scan_input();
table.set_index(col_name);
table.sort();
table.display();
}