libabacus/include/reserved.h

59 lines
1.6 KiB
C
Raw Permalink Normal View History

#ifndef LIBABACUS_RESERVED_H
#define LIBABACUS_RESERVED_H
2018-04-21 14:09:01 -07:00
#include "libabacus.h"
#include "parsetype.h"
2018-04-21 14:09:01 -07:00
#include "result.h"
#include "tree.h"
/**
* Struct that represents a reserved operator that contains
* interpreter-internal behavior.
*/
struct libab_reserved_operator_s {
/**
* The reserved operator.
*/
const char* op;
/**
* The precedence of this operator.
*/
int precedence;
/**
* The associativity of this operator.
*/
int associativity;
2018-06-21 19:00:45 -07:00
/**
* The function this operator performs.
*/
libab_result (*function)(libab*, libab_ref*, libab_tree*,
libab_tree*, libab_ref*);
};
typedef struct libab_reserved_operator_s libab_reserved_operator;
/**
* Attempts to find a reserved operator with the given name.
* This function operates under the assumption that there are
* few reserved operators in libabacus. As such, it does effectively
2018-04-21 14:09:01 -07:00
* a polynomial time search - strcmp for every element until the operator is
* found.
* @param name the name to search for.
* @return the reserved operator, if it is found.
*/
const libab_reserved_operator* libab_find_reserved_operator(const char* name);
2018-03-16 23:09:11 -07:00
/**
* Registers the existing reserved operators into the given lexer.
* @param lexer the lexer to register into.
* @return the result of the registration.
*/
libab_result libab_register_reserved_operators(libab_lexer* lexer);
/**
* Remove the existing reserved operators from the given lexer.
* @param lexer the lexer to remove from.
* @return the result of the removal.
*/
libab_result libab_remove_reserved_operators(libab_lexer* lexer);
#endif