diff --git a/include/custom.h b/include/custom.h index 0bb83df..46eb0b5 100644 --- a/include/custom.h +++ b/include/custom.h @@ -17,6 +17,10 @@ struct libab_operator_s { * The precedence of the operator. */ int precedence; + /** + * The associativity of the operator. + */ + int associativity; /** * The functionality of the operator. */ diff --git a/include/libabacus.h b/include/libabacus.h index e1fe1a8..728d523 100644 --- a/include/libabacus.h +++ b/include/libabacus.h @@ -45,10 +45,11 @@ libab_result libab_init(libab* ab); * @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 associativity the associativity 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_infix(libab* ab, const char* op, int precedence, libab_function_ptr func); +libab_result libab_register_operator_infix(libab* ab, const char* op, int precedence, int associativity, libab_function_ptr func); /** * Registers an operation with libabacus that appears * before its operand. diff --git a/src/libabacus.c b/src/libabacus.c index b0dba88..1cd43be 100644 --- a/src/libabacus.c +++ b/src/libabacus.c @@ -8,7 +8,7 @@ libab_result libab_init(libab* ab) { return libab_lexer_init(&ab->lexer); } -libab_result _register_operator(libab* ab, const char* op, int token_type, int precedence, libab_function_ptr func) { +libab_result _register_operator(libab* ab, const char* op, int token_type, int precedence, int associativity, libab_function_ptr func) { libab_result result = LIBAB_SUCCESS; libab_table_entry* new_entry; if((new_entry = malloc(sizeof(*new_entry)))) { @@ -35,16 +35,16 @@ libab_result _register_operator(libab* ab, const char* op, int token_type, int p return result; } -libab_result libab_register_operator_infix(libab* ab, const char* op, int precedence, libab_function_ptr func) { - return _register_operator(ab, op, TOKEN_OP_INFIX, precedence, func); +libab_result libab_register_operator_infix(libab* ab, const char* op, int precedence, int associativity, libab_function_ptr func) { + return _register_operator(ab, op, TOKEN_OP_INFIX, precedence, associativity, func); } libab_result libab_register_operator_prefix(libab* ab, const char* op, libab_function_ptr func) { - return _register_operator(ab, op, TOKEN_OP_PREFIX, 0, func); + return _register_operator(ab, op, TOKEN_OP_PREFIX, 0, 0, func); } libab_result libab_register_operator_postfix(libab* ab, const char* op, libab_function_ptr func) { - return _register_operator(ab, op, TOKEN_OP_POSTFIX, 0, func); + return _register_operator(ab, op, TOKEN_OP_POSTFIX, 0, 0, func); } libab_result libab_register_function(libab* ab, const char* name, libab_function_ptr func) {