Synopsis - Cross-Reference

File: /tests/Cxx/src/Parser.cc
 1#include <Synopsis/Trace.hh>
 2#include <Synopsis/Buffer.hh>
 3#include <Synopsis/Lexer.hh>
 4#include <Synopsis/SymbolFactory.hh>
 5#include <Synopsis/Parser.hh>
 6#include <Synopsis/PTree.hh>
 7#include <Synopsis/PTree/Display.hh>
 8#include <fstream>
 9
10using namespace Synopsis;
11
12int main(int argc, char **argv)
13{
14  if (argc < 3)
15  {
16    std::cerr << "Usage: " << argv[0] << " [-d] <output> <input>" << std::endl;
17    exit(-1);
18  }
19  try
20  {
21    std::string output;
22    std::string input;
23    if (argv[1] == std::string("-d"))
24    {
25      Trace::enable(Trace::ALL);
26      output = argv[2];
27      input = argv[3];
28    }
29    else
30    {
31      output = argv[1];
32      input = argv[2];
33    }
34    std::ofstream ofs(output.c_str());
35    std::ifstream ifs(input.c_str());
36    Buffer buffer(ifs.rdbuf(), input);
37    Lexer lexer(&buffer);
38    SymbolFactory symbols;
39    Parser parser(lexer, symbols);
40    PTree::Node *node = parser.parse();
41    PTree::display(node, ofs, true);
42  }
43  catch (std::exception const &e)
44  {
45    std::cerr << "Caught exception : " << e.what() << std::endl;
46  }
47}