Example #1
0
int main(int argc, char* argv[])
{
  if (argc != 2) {
      cout << "No input files!" << std::endl;
      return 1;
    }
  ifstream f(argv[1]);
  if (!f) {
      cout << "Cannot open file: " << argv[1] << std::endl;
      return 1;
    }

  QFile file_syntax(":/plsql.rules");
  if (!file_syntax.open(QIODevice::ReadOnly | QIODevice::Text))
  {
      return 1;
  }
  QTextStream syntax_input(&file_syntax);
  Syntax syntax;

  syntax.readRules(syntax_input);
  syntax.print();

  LexicalAnalyzer lexems(f);
//    auto input_name = argv[1];
//    try {
//      while(true) {
//          LexemPtr lexem = lexems.nextLexem();
//          prinLexem(lexem,cout);
//        }
//    } catch (const LexicalExceptionEndOfStream&) {
//      cout << input_name
//             << ':' << lexems.currentReadPos().row
//             << ':' << lexems.currentReadPos().column << ": "
//             <<"End of file reached." << std::endl;
//    } catch (const LexicalException& e) {
//      cout << input_name
//             << ':' << lexems.currentReadPos().row
//             << ':' << lexems.currentReadPos().column << ": "
//             << "Lexical error: " << e.what() << std::endl;
//    }
//    lexems.setCurrentLexemIndex(0);
  try {
    syntax.buildTree(lexems);
  } catch (const SyntaxException& e) {
    cout << e.what() << std::endl;
    return 1;
  } catch (const LexicalException& e) {
    cout << e.what() << std::endl;
    return 1;
  }
  syntax.getCurTree()->print();
  cout << std::endl;

  Context context;

  try {
    context.parseBlocks(syntax.getCurTree());
    context.parseVariablesInCurrentBlocks();
    context.printVariablesInCurrentBlocks();
  } catch (const ContextException& e) {
    cout << e.what() << std::endl;
    return 1;
  }

  CodeGenerator code;
  code.generate(syntax.getCurTree());
  cout << std::endl
       << STR("Generated code:") << std::endl
       << code << std::endl;

  return 0;
}