本文整理汇总了C++中DFA::getErrors方法的典型用法代码示例。如果您正苦于以下问题:C++ DFA::getErrors方法的具体用法?C++ DFA::getErrors怎么用?C++ DFA::getErrors使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DFA
的用法示例。
在下文中一共展示了DFA::getErrors方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
CGTFile cgtFile;
char *source;
Symbol *rdc;
DFA *dfa;
LALR *lalr;
ErrorTable *myErrors;
SimpleErrorRep myReporter;
// Load grammar file
if (cgtFile.load ("simple.cgt")) {
wprintf (L"%s\n", "Grammar loaded succesfully");
cgtFile.printInfo ();
} else {
wprintf (L"%s\n", "error loading file");
return -1;
}
// Load source file
char *filename = "test1.s";
source = load_source (filename);
if (source == NULL) {
wprintf (L"Error loading source file\n");
return -1;
}
// Get DFA (Deterministic Finite Automata) from the cgt file
dfa = cgtFile.getScanner();
// Scan the source in search of tokens
dfa->scan(source);
delete [] source;
// Get the error table
myErrors = dfa->getErrors();
// If there are errors report them
if (myErrors->errors.size() > 0) {
for (unsigned int i=0; i < myErrors->errors.size(); i++) {
cout << filename << ":";
cout << myReporter.composeErrorMsg (*myErrors->errors[i]) << endl;
}
return -1;
}
// Get the tokens to feed the LALR machine with them
vector <Token*> tokens = dfa->getTokens();
printTokens (tokens);
// Get the LALR (Look Ahead, Left-to-right parse, Rightmost-derivation)
lalr = cgtFile.getParser();
// Parse the tokens
rdc = lalr->parse (tokens, true, true);
myErrors = lalr->getErrors();
if (myErrors->errors.size() != 0) {
for (unsigned int i=0; i < myErrors->errors.size(); i++) {
cout << filename << ":";
cout << myReporter.composeErrorMsg (*myErrors->errors[i]) << endl;
}
return -1;
}
lalr->printReductionTree(rdc, 0);
delete rdc;
return EXIT_SUCCESS;
}