From 0b9f25bfe07ead2164641f56a957f4c4be43b64f Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 10 Apr 2016 10:34:52 -0400 Subject: [PATCH] lex: Added test harness for lexer --- CMakeLists.txt | 2 +- src/.gitignore | 4 +++- src/CMakeLists.txt | 3 +++ src/lex.cpp | 20 ++++++++++++++++++++ 4 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 src/lex.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index cb0eb675..d53a6b5e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,6 +60,6 @@ set (CPACK_SOURCE_PACKAGE_FILE_NAME ${PACKAGE_NAME}-${PACKAGE_VERSION}) set (CPACK_SOURCE_IGNORE_FILES "CMakeCache" "CMakeFiles" "CPackConfig" "CPackSourceConfig" "_CPack_Packages" "cmake_install" "install_manifest" "Makefile$" "test" "package-config" "src/timew$" "src/libtimew.a" - "src/commands/libcommands.a" + "src/commands/libcommands.a" "src/lex" "/\\\\.gitignore" "/\\\\.git/" "swp$") include (CPack) diff --git a/src/.gitignore b/src/.gitignore index cf6d9720..77ddd9c0 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -1,6 +1,8 @@ timew -gr +lex *.a CMakeFiles Makefile cmake_install.cmake +lr0 +sax diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 92b8275b..b2aa43b7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -41,10 +41,13 @@ set (libshared_SRCS libshared/src/Args.cpp libshared/src/Args.h add_library (timew STATIC ${timew_SRCS}) add_library (libshared STATIC ${libshared_SRCS}) add_executable (timew_executable timew.cpp) +add_executable (lex_executable lex.cpp) target_link_libraries (timew_executable timew libshared commands timew libshared ${TIMEW_LIBRARIES}) +target_link_libraries (lex_executable timew libshared libshared ${TIMEW_LIBRARIES}) set_property (TARGET timew_executable PROPERTY OUTPUT_NAME "timew") +set_property (TARGET lex_executable PROPERTY OUTPUT_NAME "lex") install (TARGETS timew_executable DESTINATION bin) diff --git a/src/lex.cpp b/src/lex.cpp new file mode 100644 index 00000000..2a968627 --- /dev/null +++ b/src/lex.cpp @@ -0,0 +1,20 @@ +//////////////////////////////////////////////////////////////////////////////// + +#include +#include + +int main (int argc, char** argv) +{ + for (auto i = 1; i < argc; i++) + { + std::cout << "argument '" << argv[i] << "'\n"; + + Lexer l (argv[i]); + std::string token; + Lexer::Type type; + while (l.token (token, type)) + std::cout << " token '" << token << "' " << Lexer::typeToString (type) << "\n"; + } +} + +////////////////////////////////////////////////////////////////////////////////