diff --git a/CMakeLists.txt b/CMakeLists.txt index 4372b92..8fe7bdd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,14 @@ project(libabacus) add_compile_options(-pedantic -Wall) +add_library(abacus STATIC src/lexer.c) add_executable(libabacus src/main.c) +add_subdirectory(external/liblex) +set_property(TARGET abacus PROPERTY C_STANDARD 90) set_property(TARGET libabacus PROPERTY C_STANDARD 90) +target_include_directories(abacus PUBLIC include) target_include_directories(libabacus PUBLIC include) + +target_link_libraries(abacus lex) +target_link_libraries(libabacus abacus) diff --git a/include/lexer.h b/include/lexer.h new file mode 100644 index 0000000..f816ce7 --- /dev/null +++ b/include/lexer.h @@ -0,0 +1,37 @@ +#ifndef LIBABACUS_LEXER_H +#define LIBABACUS_LEXER_H + +#include "eval.h" +#include "libabacus.h" + +/** + * The lexer used for reading + * a string and converting it into + * tokens. + */ +struct lexer { + /** + * The liblex configuration used + * to convert the string into tokens. + */ + eval_config config; +}; + +typedef struct lexer lexer; + +/** + * Initializes the given lexer, + * placing the default tokens into it. + * @param lexer the lexer to intiailize. + * @return the result of the operation (can be MALLOC on failed allocation.) + */ +libab_result lexer_init(lexer* lexer); +/** + * Releases the memory associated with the given lexer, + * removing all registered patterns from it. + * @param lexer the lexer to free. + * @return the result of the operation. + */ +libab_result lexer_free(lexer* lexer); + +#endif diff --git a/include/libabacus.h b/include/libabacus.h new file mode 100644 index 0000000..e74312d --- /dev/null +++ b/include/libabacus.h @@ -0,0 +1,15 @@ +#ifndef LIBABACUS_H +#define LIBABACUS_H + +/** + * An enum that represents the outcomes of + * libabacus functions that can fail. + */ +enum libab_result { + LIBAB_SUCCESS, + LIBAB_MALLOC +}; + +typedef enum libab_result libab_result; + +#endif diff --git a/src/lexer.c b/src/lexer.c new file mode 100644 index 0000000..723ab1d --- /dev/null +++ b/src/lexer.c @@ -0,0 +1 @@ +#include "lexer.h"