From d52c1fb406b1cef82c5f5a28fc1804d7d99a49d8 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 17 Nov 2016 01:35:29 +0300 Subject: Add support for build2 for tests and examples --- unit-tests/lexer/driver.cxx | 123 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 unit-tests/lexer/driver.cxx (limited to 'unit-tests/lexer/driver.cxx') diff --git a/unit-tests/lexer/driver.cxx b/unit-tests/lexer/driver.cxx new file mode 100644 index 0000000..471bc1b --- /dev/null +++ b/unit-tests/lexer/driver.cxx @@ -0,0 +1,123 @@ +// file : unit-tests/lexer/driver.cxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#include +#include + +#include +#include + +using namespace std; + +const char* keywords[] = +{ + "source", + "include", + "namespace", + "class", + "signed", + "unsigned", + "bool", + "char", + "wchar_t", + "short", + "int", + "long", + "float", + "double" +}; + +const char* punctuation[] = { + ";", ",", ":", "::", "{", "}", /*"(", ")",*/ "=", "|"}; + +int +main (int argc, char* argv[]) +{ + if (argc != 2) + { + cerr << "usage: " << argv[0] << " file.cli" << endl; + return 1; + } + + ifstream ifs; + ifs.exceptions (ifstream::failbit | ifstream::badbit); + ifs.open (argv[1]); + + lexer l (ifs, argv[1]); + + while (true) + { + token t (l.next ()); + + switch (t.type ()) + { + case token::t_eos: + { + cout << "" << endl; + return 0; + } + case token::t_keyword: + { + cout << "keyword: " << keywords[t.keyword ()] << endl; + break; + } + case token::t_identifier: + { + cout << "identifier: " << t.identifier () << endl; + break; + } + case token::t_punctuation: + { + cout << punctuation[t.punctuation ()] << endl; + break; + } + case token::t_cxx_path_lit: + { + cout << "c++ path: " << t.literal () << endl; + break; + } + case token::t_cli_path_lit: + { + cout << "cli path: " << t.literal () << endl; + break; + } + case token::t_string_lit: + { + cout << t.literal () << endl; + break; + } + case token::t_char_lit: + { + cout << t.literal () << endl; + break; + } + case token::t_bool_lit: + { + cout << t.literal () << endl; + break; + } + case token::t_int_lit: + { + cout << t.literal () << endl; + break; + } + case token::t_float_lit: + { + cout << t.literal () << endl; + break; + } + case token::t_call_expr: + { + cout << t.expression () << endl; + break; + } + case token::t_template_expr: + { + cout << t.expression () << endl; + break; + } + } + } +} -- cgit v1.1