| 
									
										
										
										
											2018-02-10 13:52:33 -08:00
										 |  |  | #ifndef LIBABACUS_H
 | 
					
						
							|  |  |  | #define LIBABACUS_H
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-21 14:09:01 -07:00
										 |  |  | #include "custom.h"
 | 
					
						
							| 
									
										
										
										
											2018-02-11 21:52:28 -08:00
										 |  |  | #include "ht.h"
 | 
					
						
							|  |  |  | #include "lexer.h"
 | 
					
						
							| 
									
										
										
										
											2018-02-11 22:23:02 -08:00
										 |  |  | #include "parser.h"
 | 
					
						
							| 
									
										
										
										
											2018-04-24 11:35:27 -07:00
										 |  |  | #include "interpreter.h"
 | 
					
						
							| 
									
										
										
										
											2018-02-11 22:32:42 -08:00
										 |  |  | #include "result.h"
 | 
					
						
							| 
									
										
										
										
											2018-04-21 14:09:01 -07:00
										 |  |  | #include "table.h"
 | 
					
						
							| 
									
										
										
										
											2018-04-24 16:59:53 -07:00
										 |  |  | #include "impl.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-04-24 11:35:27 -07:00
										 |  |  |     /**
 | 
					
						
							|  |  |  |      * The interpreter used | 
					
						
							|  |  |  |      * to run a tree. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     libab_interpreter intr; | 
					
						
							| 
									
										
										
										
											2018-02-11 21:52:28 -08:00
										 |  |  |     /**
 | 
					
						
							|  |  |  |      * The table used to store top-level | 
					
						
							|  |  |  |      * things like functions and operators. | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-04-24 11:32:57 -07:00
										 |  |  |     libab_ref table; | 
					
						
							| 
									
										
										
										
											2018-04-24 16:59:53 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /**
 | 
					
						
							|  |  |  |      * The allocator used to construct number instances. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     libab_impl impl; | 
					
						
							| 
									
										
										
										
											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. | 
					
						
							| 
									
										
										
										
											2018-02-17 16:00:39 -08:00
										 |  |  |  * @param associativity the associativity of the operator. | 
					
						
							| 
									
										
										
										
											2018-03-15 19:41:11 -07:00
										 |  |  |  * @param type the type of this operator. | 
					
						
							| 
									
										
										
										
											2018-02-11 21:52:28 -08:00
										 |  |  |  * @param func the function that describes the functionality of the operator. | 
					
						
							|  |  |  |  * @return the result of the initialization. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-04-21 14:09:01 -07:00
										 |  |  | libab_result libab_register_operator_infix(libab* ab, const char* op, | 
					
						
							|  |  |  |                                            int precedence, int associativity, | 
					
						
							|  |  |  |                                            libab_ref* type, | 
					
						
							|  |  |  |                                            libab_function_ptr func); | 
					
						
							| 
									
										
										
										
											2018-02-17 14:00:37 -08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Registers an operation with libabacus that appears | 
					
						
							|  |  |  |  * before its operand. | 
					
						
							|  |  |  |  * @param ab the libabacus instance to register the operator with. | 
					
						
							|  |  |  |  * @param op the operator string to register. | 
					
						
							| 
									
										
										
										
											2018-03-15 19:41:11 -07:00
										 |  |  |  * @param type the type of this operator. | 
					
						
							| 
									
										
										
										
											2018-02-17 14:00:37 -08:00
										 |  |  |  * @param func the function that describes the functionality of the operator. | 
					
						
							|  |  |  |  * @return the result of the registration. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-04-21 14:09:01 -07:00
										 |  |  | libab_result libab_register_operator_prefix(libab* ab, const char* op, | 
					
						
							|  |  |  |                                             libab_ref* type, | 
					
						
							|  |  |  |                                             libab_function_ptr func); | 
					
						
							| 
									
										
										
										
											2018-02-17 14:00:37 -08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Registers an operation with libabacus that appears | 
					
						
							|  |  |  |  * after its operand. | 
					
						
							|  |  |  |  * @param ab the libabacus instance to register the operator with. | 
					
						
							|  |  |  |  * @param op the operator string to register. | 
					
						
							| 
									
										
										
										
											2018-03-15 19:41:11 -07:00
										 |  |  |  * @param type the type of this operator. | 
					
						
							| 
									
										
										
										
											2018-02-17 14:00:37 -08:00
										 |  |  |  * @param func the function that describes the functionality of the operator. | 
					
						
							|  |  |  |  * @return the result of the registration. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-04-21 14:09:01 -07:00
										 |  |  | libab_result libab_register_operator_postfix(libab* ab, const char* op, | 
					
						
							|  |  |  |                                              libab_ref* type, | 
					
						
							|  |  |  |                                              libab_function_ptr func); | 
					
						
							| 
									
										
										
										
											2018-02-17 14:00:37 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-11 21:52:28 -08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Registers a function with libabacus. | 
					
						
							|  |  |  |  * @param ab the libabacus instance used to keep state. | 
					
						
							|  |  |  |  * @param name the name of the function. | 
					
						
							| 
									
										
										
										
											2018-03-15 19:41:11 -07:00
										 |  |  |  * @param type the type of this operator. | 
					
						
							| 
									
										
										
										
											2018-02-11 21:52:28 -08:00
										 |  |  |  * @param func the function that describes the functionality of the function. | 
					
						
							| 
									
										
										
										
											2018-04-17 12:07:22 -07:00
										 |  |  |  * @return the result of the registration. | 
					
						
							| 
									
										
										
										
											2018-02-11 21:52:28 -08:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-04-21 14:09:01 -07:00
										 |  |  | libab_result libab_register_function(libab* ab, const char* name, | 
					
						
							|  |  |  |                                      libab_ref* type, libab_function_ptr func); | 
					
						
							| 
									
										
										
										
											2018-04-17 12:07:22 -07:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Registers a base type with abacus. | 
					
						
							|  |  |  |  * @param ab the libabacus instance used to keep state. | 
					
						
							|  |  |  |  * @param name the name to register the basetype under. | 
					
						
							|  |  |  |  * @param basetype the basetype to register. | 
					
						
							|  |  |  |  * @return the result of the registration. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-04-21 14:09:01 -07:00
										 |  |  | libab_result libab_register_basetype(libab* ab, const char* name, | 
					
						
							|  |  |  |                                      libab_basetype* basetype); | 
					
						
							| 
									
										
										
										
											2018-04-20 14:54:23 -07:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Constructs and resolves a parse type, similarly to how it's done in the | 
					
						
							|  |  |  |  * parser. | 
					
						
							|  |  |  |  * @param ab the libab instance to use for constructing the type. | 
					
						
							|  |  |  |  * @param into the reference to populate with the given type. | 
					
						
							|  |  |  |  * @param type the type to parse. | 
					
						
							|  |  |  |  * @return the result of the operation. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | libab_result libab_create_type(libab* ab, libab_ref* into, const char* type); | 
					
						
							| 
									
										
										
										
											2018-02-11 21:52:28 -08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * 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
 |