From 257ad3c2c5e633d2fd3f2228021ac3ae8d6d07cb Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 12 Dec 2014 11:30:04 +0200 Subject: Initial buildfile parser implementation g++-4.9 -std=c++14 -g -I../../.. -o driver driver.cxx ../../../build/lexer.cxx ../../../build/parser.cxx && ./driver --- build/bd.cxx | 35 +++++++---------------------------- 1 file changed, 7 insertions(+), 28 deletions(-) (limited to 'build/bd.cxx') diff --git a/build/bd.cxx b/build/bd.cxx index 33ee02f..82d283c 100644 --- a/build/bd.cxx +++ b/build/bd.cxx @@ -16,8 +16,8 @@ #include #include -#include #include +#include using namespace std; @@ -148,41 +148,20 @@ main (int argc, char* argv[]) } ifs.exceptions (ifstream::failbit | ifstream::badbit); - lexer l (ifs, bf.string ()); + parser p; try { - for (token t (l.next ());; t = l.next ()) - { - cout << t.line () << ':' << t.column () << ": "; - - switch (t.type ()) - { - case token_type::eos: cout << ""; break; - case token_type::punctuation: - { - switch (t.punctuation ()) - { - case token_punctuation::newline: cout << "\\n"; break; - case token_punctuation::colon: cout << ':'; break; - case token_punctuation::lcbrace: cout << '{'; break; - case token_punctuation::rcbrace: cout << '}'; break; - } - break; - } - case token_type::name: cout << '\'' << t.name () << '\''; break; - } - - cout << endl; - - if (t.type () == token_type::eos) - break; - } + p.parse (ifs, bf); } catch (const lexer_error&) { return 1; // Diagnostics has already been issued. } + catch (const parser_error&) + { + return 1; // Diagnostics has already been issued. + } catch (const std::ios_base::failure&) { cerr << "error: failed to read from " << bf << endl; -- cgit v1.1