summaryrefslogtreecommitdiff
path: root/cli/cli.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2009-08-22 10:25:38 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2009-08-22 10:25:38 +0200
commit2a24763c6fd6a75510ded0d030620aad1eba2b02 (patch)
tree0077871a7bf60cccde35c0699cde2f573dfe74aa /cli/cli.cxx
parentfabbe60b014a02b2ab94e57ab3866e28c67d36ce (diff)
Change the compiler driver to call the parser
Diffstat (limited to 'cli/cli.cxx')
-rw-r--r--cli/cli.cxx37
1 files changed, 35 insertions, 2 deletions
diff --git a/cli/cli.cxx b/cli/cli.cxx
index a25bc1c..b070913 100644
--- a/cli/cli.cxx
+++ b/cli/cli.cxx
@@ -3,11 +3,44 @@
// copyright : Copyright (c) 2009 Code Synthesis Tools CC
// license : MIT; see accompanying LICENSE file
+#include <fstream>
#include <iostream>
+#include "parser.hxx"
+
using namespace std;
-int main ()
+int main (int argc, char* argv[])
{
- cerr << "CLI compiler driver" << endl;
+ if (argc != 2)
+ {
+ cerr << "usage: " << argv[0] << " file.cli" << endl;
+ return 1;
+ }
+
+ try
+ {
+ ifstream ifs (argv[1]);
+ if (!ifs.is_open ())
+ {
+ wcerr << argv[1] << ": error: unable to open in read mode" << endl;
+ return 1;
+ }
+
+ ifs.exceptions (ifstream::failbit | ifstream::badbit);
+
+ Parser parser;
+ parser.parse (ifs, argv[1]);
+ }
+ catch (std::ios_base::failure const&)
+ {
+ wcerr << argv[1] << ": error: read failure" << endl;
+ return 1;
+ }
+ catch (Parser::InvalidInput const&)
+ {
+ // Diagnostics has already been issued by the parser.
+ //
+ return 1;
+ }
}