当前位置: 首页>>代码示例>>C++>>正文


C++ DFA::getErrors方法代码示例

本文整理汇总了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;
}
开发者ID:jimmason101,项目名称:cpp-gpengine,代码行数:73,代码来源:simple.cpp


注:本文中的DFA::getErrors方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。