本文整理汇总了C++中Analyser::AnalyseLexical方法的典型用法代码示例。如果您正苦于以下问题:C++ Analyser::AnalyseLexical方法的具体用法?C++ Analyser::AnalyseLexical怎么用?C++ Analyser::AnalyseLexical使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Analyser
的用法示例。
在下文中一共展示了Analyser::AnalyseLexical方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
LR0_Analyser la;
la.AddProduction("E", "E", "+", "E");
la.AddProduction("E", "E", "*", "E");
la.AddProduction("E", "(", "E", ")");
la.AddProduction("E", "i");
la.AddAction(0, "(", 'S', 2);
la.AddAction(0, "i", 'S', 3);
la.AddAction(1, "+", 'S', 4);
la.AddAction(1, "*", 'S', 5);
la.AddAction(1, LR0_Analyser::END_OF_INPUT, 'A', 0);
la.AddAction(2, "(", 'S', 2);
la.AddAction(2, "i", 'S', 3);
la.AddAction(3, "+", 'r', 4);
la.AddAction(3, "*", 'r', 4);
la.AddAction(3, ")", 'r', 4);
la.AddAction(3, LR0_Analyser::END_OF_INPUT, 'r', 4);
la.AddAction(4, "(", 'S', 2);
la.AddAction(4, "i", 'S', 3);
la.AddAction(5, "(", 'S', 2);
la.AddAction(5, "i", 'S', 3);
la.AddAction(6, "+", 'S', 4);
la.AddAction(6, "*", 'S', 5);
la.AddAction(6, ")", 'S', 9);
la.AddAction(7, "+", 'r', 1);
la.AddAction(7, "*", 'S', 5);
la.AddAction(7, ")", 'r', 1);
la.AddAction(7, LR0_Analyser::END_OF_INPUT, 'r', 1);
la.AddAction(8, "+", 'r', 2);
la.AddAction(8, "*", 'r', 2);
la.AddAction(8, ")", 'r', 2);
la.AddAction(8, LR0_Analyser::END_OF_INPUT, 'r', 2);
la.AddAction(9, "+", 'r', 3);
la.AddAction(9, "*", 'r', 3);
la.AddAction(9, ")", 'r', 3);
la.AddAction(9, LR0_Analyser::END_OF_INPUT, 'r', 3);
la.AddGoto(0, "E", 1);
la.AddGoto(2, "E", 6);
la.AddGoto(4, "E", 7);
la.AddGoto(5, "E", 8);
Analyser analyser;
string input_string;
while (cout << "Input expression: ", getline(cin, input_string))
{
vector<pair<string, string>> lex_result = analyser.AnalyseLexical(input_string);
int error_index = -1;
for (size_t i = 0; i < lex_result.size(); ++i)
{
if (lex_result[i].second == "unknown")
error_index = i;
}
if (error_index != -1)
{
cout << "Error on: " << lex_result[error_index].first << endl;
continue;
}
vector<pair<string, string>> escape_result = Escape(lex_result);
la.Input(escape_result);
if ((error_index = la.Analyse()) != -1)
{
if (error_index == lex_result.size())
cout << "Error on: the end of input" << endl;
else
cout << "Error on: " << lex_result[error_index].first << endl;
continue;
}
cout << "Right!" << endl;;
}
}