Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 )
7 changes: 1 addition & 6 deletions lexer.rl
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
#include <stdlib.h>
#include "parser.c"

std::string getStr(const char* beg, const char* end)
{
return std::string(beg).substr(0, end-beg);
}


%%{

Expand Down Expand Up @@ -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]+)?;
Expand Down