Begin working on the lexer.

This commit is contained in:
Danila Fedorin 2018-02-10 13:52:33 -08:00
parent 29ae1ce5b4
commit 10652048ab
4 changed files with 60 additions and 0 deletions

View File

@ -8,7 +8,14 @@ project(libabacus)
add_compile_options(-pedantic -Wall) add_compile_options(-pedantic -Wall)
add_library(abacus STATIC src/lexer.c)
add_executable(libabacus src/main.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) set_property(TARGET libabacus PROPERTY C_STANDARD 90)
target_include_directories(abacus PUBLIC include)
target_include_directories(libabacus PUBLIC include) target_include_directories(libabacus PUBLIC include)
target_link_libraries(abacus lex)
target_link_libraries(libabacus abacus)

37
include/lexer.h Normal file
View File

@ -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

15
include/libabacus.h Normal file
View File

@ -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

1
src/lexer.c Normal file
View File

@ -0,0 +1 @@
#include "lexer.h"