2018-02-10 13:52:33 -08:00
|
|
|
#ifndef LIBABACUS_H
|
|
|
|
#define LIBABACUS_H
|
|
|
|
|
2018-02-11 21:52:28 -08:00
|
|
|
#include "ht.h"
|
|
|
|
#include "lexer.h"
|
|
|
|
#include "table.h"
|
2018-02-11 22:23:02 -08:00
|
|
|
#include "parser.h"
|
2018-02-11 22:32:42 -08:00
|
|
|
#include "result.h"
|
2018-02-11 22:34:46 -08:00
|
|
|
#include "custom.h"
|
2018-02-11 21:52:28 -08:00
|
|
|
|
2018-02-10 13:52:33 -08:00
|
|
|
/**
|
2018-02-11 21:52:28 -08:00
|
|
|
* The main struct of libabacus,
|
|
|
|
* which essentially holds all the informatiom
|
|
|
|
* for the library's state and operation.
|
2018-02-10 13:52:33 -08:00
|
|
|
*/
|
2018-02-11 21:52:28 -08:00
|
|
|
struct libab_s {
|
|
|
|
/**
|
|
|
|
* The lexer used to convert a string
|
|
|
|
* to tokens.
|
|
|
|
*/
|
|
|
|
libab_lexer lexer;
|
2018-02-11 22:23:02 -08:00
|
|
|
/**
|
|
|
|
* The parser used to convert
|
|
|
|
* tokens to a tree.
|
|
|
|
*/
|
|
|
|
libab_parser parser;
|
2018-02-11 21:52:28 -08:00
|
|
|
/**
|
|
|
|
* The table used to store top-level
|
|
|
|
* things like functions and operators.
|
|
|
|
*/
|
|
|
|
libab_table table;
|
2018-02-10 13:52:33 -08:00
|
|
|
};
|
|
|
|
|
2018-02-11 21:52:28 -08:00
|
|
|
typedef struct libab_s libab;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes the libabacus struct as well
|
|
|
|
* as all its internal structures such as the lexer.
|
|
|
|
* @param ab the libabacus instance used to keep state.
|
|
|
|
* @return the result of the initialization.
|
|
|
|
*/
|
|
|
|
libab_result libab_init(libab* ab);
|
|
|
|
/**
|
|
|
|
* Registers an operator with libabacus.
|
|
|
|
* @param ab the libabacus instance to reigster the operator with.
|
|
|
|
* @param op the operator string to register.
|
|
|
|
* @param precedence the precedence of the operator.
|
|
|
|
* @param func the function that describes the functionality of the operator.
|
|
|
|
* @return the result of the initialization.
|
|
|
|
*/
|
|
|
|
libab_result libab_register_operator(libab* ab, const char* op, int precedence, libab_function_ptr func);
|
|
|
|
/**
|
|
|
|
* Registers a function with libabacus.
|
|
|
|
* @param ab the libabacus instance used to keep state.
|
|
|
|
* @param name the name of the function.
|
|
|
|
* @param func the function that describes the functionality of the function.
|
|
|
|
* @return the result of the initialization.
|
|
|
|
*/
|
|
|
|
libab_result libab_register_function(libab* ab, const char* name, libab_function_ptr func);
|
|
|
|
/**
|
|
|
|
* Releases all the resources allocated by libabacus.
|
|
|
|
* @param ab the libabacus instance to release.
|
|
|
|
* @return the result of the initialization.
|
|
|
|
*/
|
|
|
|
libab_result libab_free(libab* ab);
|
2018-02-10 13:52:33 -08:00
|
|
|
|
|
|
|
#endif
|