diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..7fe4d58 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,34 @@ +cmake_minimum_required(VERSION 2.8) +PROJECT(simplecalc) + + +# copy parser.y to build directory. We want a shaddow build that does not litter +# the source directory +add_custom_command( + OUTPUT ${CMAKE_BINARY_DIR}/parser.y + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/parser.y ${CMAKE_BINARY_DIR}/parser.y + DEPENDS ${CMAKE_SOURCE_DIR}/parser.y) + +# run lemon +add_custom_target(parser + COMMAND lemon ${CMAKE_BINARY_DIR}/parser.y + DEPENDS ${CMAKE_BINARY_DIR}/parser.y + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} +) + +# run ragel +add_custom_command( + OUTPUT ${CMAKE_BINARY_DIR}/lexer.cpp + COMMAND ragel ${CMAKE_SOURCE_DIR}/lexer.rl -o ${CMAKE_BINARY_DIR}/lexer.cpp + DEPENDS ${CMAKE_SOURCE_DIR}/lexer.rl +) + +add_custom_target(IDE SOURCES + parser.y + lexer.rl + ) + +# build executable +add_executable(calc ${CMAKE_BINARY_DIR}/lexer.cpp) + +add_dependencies(calc parser ) diff --git a/lexer.rl b/lexer.rl index f1413b8..ee19601 100644 --- a/lexer.rl +++ b/lexer.rl @@ -6,11 +6,6 @@ #include #include "parser.c" -std::string getStr(const char* beg, const char* end) -{ - return std::string(beg).substr(0, end-beg); -} - %%{ @@ -46,7 +41,7 @@ action closep_tok { } action number_tok{ - Parse(lparser, DOUBLE, atof(getStr(ts, te).c_str())); + Parse(lparser, DOUBLE, atof(std::string(ts, te).c_str())); } number = [0-9]+('.'[0-9]+)?;