/*
 * Copyright (c) 2011, Robert E. Cousins
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the <organization> nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * $Id: exp.h,v 1.3 2011/09/06 22:06:23 rec Exp $
 */
#ifndef exp_h
#define exp_h
/*
 * Basic API
 *
 * During normal operation, the user would call exp_init() to intialize the
 * library, then call exp_eva() some number of times, then finally 
 * call exp_shutdown() to deallocate internal tables. 
 *
 * A return value of zero indicates no errors. 
 */
int
exp_init();

int
exp_shutdown();

double
exp_eval(char *expression);

/*
 * Advanced API
 *
 * If the user wishes to add operators, functions, constants or variables
 * to the expression grammar, it is quite easy to do.
 *
 * Adding an operator requires calling exp_add_operator() with the string
 * corresponding to the operator (such as '@' or "FooBall", the number of
 * arguments the operator takes (0, 1 or 2), the precidence of the operators
 * (higher numbers are higher priority), whether the operator is right
 * associative and finally a pointer to a function which implements the
 * operator. This function must directly deal with the internal stack
 * so it must call exp_num_pop() and exp_num_push() to get and return
 * values.
 */
void *
exp_add_operator(char *name,
		 int args,
		 int prec,
		 int right_associative,
		 void (*f)());
/* 
 * Adding functions is easier than operators. Simply register the name
 * of the function to be called (such as "sin" or "sqrt"), provide the
 * number of arguments (0..3 for now) and a function of the form
 *
 *   double function(double a,...);
 *
 * Note: There is no requirement that "sin" refer to the sin(3) function
 * in libm.a. If the user desires to use degrees instead of radians, suitable
 * functions can  be installed.
 */
int
exp_add_function(char *name,
		 int args,
		 double (*f)());
/*
 * Adding a constant is very simple. Simply register the name and the value.
 * The same goes for variables. (The only difference is that in the future,
 * I may add support for an assignment operator--constants will not allow
 * assignment.) As of now, variables and constants operate identically.
 */
int
exp_add_constant(char *name,
		 double value);
/*
 *  Add Variable returns a pointer to the double which holds the value
 * in case the user needs to update the value in the future;
 */
int
exp_add_variable(char *name,
		 double value);
/*
 * This is another way to update the value of a variable.
 * Returns 0 if successful, 1 if can't find variable, 2 if
 * it isn't a variable.
 */
int
exp_update_variable(char *name,
		    double new_value);
int
exp_fetch_variable(char *name,
		   double *result);
/*
 * Support API
 */
double
exp_num_pop();

void
exp_num_push(double);

void
exp_dump_symboltable();


#endif
