[an error occurred while processing this directive]
[<a href="index.shtml">Package Index</a></code> | <a href="index_std.shtml">Mudlib Index</a></code> | <a href="index_eff.shtml">Effect Index</a></code>]<br><h2>File /std/basic/expressions.c</h2>
This is an inheritable to handle certain sorts of expressions in stuff.
These expression can be setup by players (or creators) and then run
or evaluated.  It allows controlling the types usable by the expression
handlers, strings, arrays, mappings, integers and floats.<p>Written by Pinkfish<p>Started Thu May  4 22:44:34 PDT 2000
<h2>Includes</h2>
This class includes the following files <a href="include.expressions.h.shtml">/include/expressions.h</a>, /include/shops/bank.h and <a href="include.money.h.shtml">/include/money.h</a><h2>Class Index</h2>
<ul><li><a href="#class_func_variable_thing">func_variable_thing</a>
<li><a href="#class_function_thing">function_thing</a>
<li><a href="#class_user_function_thing">user_function_thing</a>
<li><a href="#class_variable_thing">variable_thing</a>
</ul><h2>Method index</h2>
<dl><ul>
<li><a href="#add_allowed_function">add_allowed_function</a>(string, int, int *, function)<br/>
This method adds in an allowed function and specifies the types it
takes.
<li><a href="#add_allowed_variable">add_allowed_variable</a>(string, int, function)<br/>
This method adds in an allowed variable and specifies it's type.
<li><a href="#evaluate_expression">evaluate_expression</a>(class parse_node *, mixed args)<br/>
This method evaluates the expression and creates a nice end result
thingy.
<li><a href="#is_alpha">is_alpha</a>(int)<br/>
This method checks to see if the passed in character is an alpha
or not.
<li><a href="#is_array_type">is_array_type</a>(int)<br/>
This checks to make sure that the type is an array.
<li><a href="#is_null_array_type">is_null_array_type</a>(int)<br/>
This checks to make sure that the type is a null array.
<li><a href="#is_number">is_number</a>(int)<br/>
This method checks to see if the passed in character is a number
or not.
<li><a href="#is_number_type">is_number_type</a>(int)<br/>
This checks to make sure that the type is a number based type.
<li><a href="#is_space">is_space</a>(int)<br/>
This method checks to see if the passed in character is a space or
a space equivilant.
<li><a href="#parse_boolean_string">parse_boolean_string</a>(string)<br/>
A very small recursive decent parser which must return a boolean
value.
<li><a href="#parse_integer_string">parse_integer_string</a>(string)<br/>
A very small recursive decent parser which must return a integer
value.
<li><a href="#parse_money_string">parse_money_string</a>(string)<br/>
A very small recursive decent parser which must return a money
value.
<li><a href="#parse_user_expression">parse_user_expression</a>(string, string)<br/>
This method attempts to parse a user expression.
<li><a href="#parse_user_expression_definition">parse_user_expression_definition</a>(string)<br/>
This will pass the arguments to a user defined function and return
an array of three elements.
<li><a href="#query_expression_string">query_expression_string</a>(class parse_node *, int)<br/>
This method returns the expresion as a string.
<li><a href="#query_function_args_types">query_function_args_types</a>(string)<br/>
This method returns the type of the function.
<li><a href="#query_function_names">query_function_names</a>()<br/>
This method returns all the function names defined in this expression
inheritable.
<li><a href="#query_function_type">query_function_type</a>(string)<br/>
This method returns the type of the function.
<li><a href="#query_function_value">query_function_value</a>(string)<br/>
This method returns the value of the function.
<li><a href="#query_function_variable_position">query_function_variable_position</a>(string)<br/>
This method returns the position of the function variable.
<li><a href="#query_function_variable_type">query_function_variable_type</a>(string)<br/>
This method returns the type of the function variable.
<li><a href="#query_last_expression_error">query_last_expression_error</a>()<br/>
This method returns the last error if there was an error in the parsing.
<li><a href="#query_last_expression_warning">query_last_expression_warning</a>()<br/>
This method returns the last warning if there was an warning in the parsing.
<li><a href="#query_null_type">query_null_type</a>(int)<br/>
This method returns a null object of the specified type.
<li><a href="#query_operator_name">query_operator_name</a>(int)<br/>
This method returns the string value of the operator name.
<li><a href="#query_token">query_token</a>(string)<br/>
This method find the next token.
<li><a href="#query_type_name">query_type_name</a>(int)<br/>
This method returns the name of the type.
<li><a href="#query_type_value">query_type_value</a>(string)<br/>
This method returns the value of the type.
<li><a href="#query_user_function_arg_names">query_user_function_arg_names</a>(string)<br/>
This method returns the argument names names of the user defined
function.
<li><a href="#query_user_function_arg_types">query_user_function_arg_types</a>(string)<br/>
This method returns the argument names types of the user defined
function.
<li><a href="#query_user_function_args">query_user_function_args</a>(string)<br/>
This method returns the argument names and types of the user defined
function.
<li><a href="#query_user_function_expression">query_user_function_expression</a>(string)<br/>
This method returns the expression of the user defined function.
<li><a href="#query_user_function_names">query_user_function_names</a>()<br/>
This method returns the list of user defined functions in the
inheritable.
<li><a href="#query_user_function_return_type">query_user_function_return_type</a>(string)<br/>
This method returns the return type of the user defined function.
<li><a href="#query_user_function_string">query_user_function_string</a>(string)<br/>
This method makes a nice string representation of the user function.
<li><a href="#query_variable_names">query_variable_names</a>()<br/>
This method returns the names of all the variables.
<li><a href="#query_variable_type">query_variable_type</a>(string)<br/>
This method returns the type of the variable.
<li><a href="#query_variable_value">query_variable_value</a>(string)<br/>
This method returns the value of the variable.
<li><a href="#remove_user_expression">remove_user_expression</a>(string)<br/>
This method removes the currently defined user expression.
<li><a href="#sizeof_function">sizeof_function</a>(mixed *, mixed args)<br/>
Does a sizeof an array.
</ul><h2>Public Functions</h2>
These are functions that everyone can access.<p>
.<ul><a name="add_allowed_function">
add_allowed_function</a><pre>
void add_allowed_function(string name,
                          int type,
                          int * args,
                          function value)
</pre></br>
This method adds in an allowed function and specifies the types it
takes.
<br/><ul>
<li><b>Parameters:</b>
<br/>name - the name of the function
<br/>type - the return type of the function
<br/>args - the types of the arguements (an array)
<br/>value - the function to call to get the value

</dl>

<ul><a name="add_allowed_variable">
add_allowed_variable</a><pre>
void add_allowed_variable(string name,
                          int type,
                          function value)
</pre></br>
This method adds in an allowed variable and specifies it's type.
<br/><ul>
<li><b>Parameters:</b>
<br/>name - the name of the variable
<br/>type - the type of the variable
<br/>value - the value of the variable

</dl>

<ul><a name="evaluate_expression">
evaluate_expression</a><pre>
class parse_node evaluate_expression(class parse_node * expr,
                                     mixed args ...)
</pre></br>
This method evaluates the expression and creates a nice end result
thingy.
<br/><ul>
<li><b>Parameters:</b>
<br/>expr - the exrpession to evaluate
<br/>args - the optional args parsed into the various function calls
<li><b>Returns:</b>
<br/>the type and value of the expression, 0 if failed

</dl>

<ul><a name="parse_boolean_string">
parse_boolean_string</a><pre>
class parse_node * parse_boolean_string(string str)
</pre></br>
A very small recursive decent parser which must return a boolean
value.
<br/><ul>
<li><b>Parameters:</b>
<br/>str - the input string
<li><b>Returns:</b>
<br/>the array control structure

</dl>

<ul><a name="parse_integer_string">
parse_integer_string</a><pre>
class parse_node * parse_integer_string(string str)
</pre></br>
A very small recursive decent parser which must return a integer
value.
<br/><ul>
<li><b>Parameters:</b>
<br/>str - the input string
<li><b>Returns:</b>
<br/>the array control structure

</dl>

<ul><a name="parse_money_string">
parse_money_string</a><pre>
class parse_node * parse_money_string(string str)
</pre></br>
A very small recursive decent parser which must return a money
value.
<br/><ul>
<li><b>Parameters:</b>
<br/>str - the input string
<li><b>Returns:</b>
<br/>the array control structure

</dl>

<ul><a name="parse_user_expression">
parse_user_expression</a><pre>
string parse_user_expression(string def,
                             string str)
</pre></br>
This method attempts to parse a user expression.
<br/><ul>
<li><b>Parameters:</b>
<br/>name - the name of the function
<br/>args - the name and types of the arguments
<br/>str - the input string
<li><b>Returns:</b>
<br/>the name of the function, 0 on failure

</dl>

<ul><a name="parse_user_expression_definition">
parse_user_expression_definition</a><pre>
mixed * parse_user_expression_definition(string def)
</pre></br>
This will pass the arguments to a user defined function and return
an array of three elements.  The first is the name of the function,
the second is the array of arguments types and the third is the array of
argument names.


<ul><a name="query_expression_string">
query_expression_string</a><pre>
string query_expression_string(class parse_node * expr,
                               int brief)
</pre></br>
This method returns the expresion as a string.
<br/><ul>
<li><b>Parameters:</b>
<br/>expr - the expression
<br/>brief - don't expand the variable names
<li><b>Returns:</b>
<br/>the expression as a string

</dl>

<ul><a name="query_function_args_types">
query_function_args_types</a><pre>
int * query_function_args_types(string name)
</pre></br>
This method returns the type of the function.
<br/><ul>
<li><b>Parameters:</b>
<br/>name - the name of the function to check
<li><b>Returns:</b>
<br/>the args of the function, null array is not found

</dl>

<ul><a name="query_function_names">
query_function_names</a><pre>
string * query_function_names()
</pre></br>
This method returns all the function names defined in this expression
inheritable.
<br/><ul>
<li><b>Returns:</b>
<br/>the function names

</dl>

<ul><a name="query_function_type">
query_function_type</a><pre>
int query_function_type(string name)
</pre></br>
This method returns the type of the function.
<br/><ul>
<li><b>Parameters:</b>
<br/>name - the name of the function to check
<li><b>Returns:</b>
<br/>the type of the function, EXPRESSION_TYPE_ERROR if there is no
function

</dl>

<ul><a name="query_function_value">
query_function_value</a><pre>
function query_function_value(string name)
</pre></br>
This method returns the value of the function.
<br/><ul>
<li><b>Parameters:</b>
<br/>name - the name of the function to find
<li><b>Returns:</b>
<br/>the value of the function, 0 if not found

</dl>

<ul><a name="query_function_variable_position">
query_function_variable_position</a><pre>
int query_function_variable_position(string name)
</pre></br>
This method returns the position of the function variable.
<br/><ul>
<li><b>Parameters:</b>
<br/>name - the name of the function variable to check
<li><b>Returns:</b>
<br/>the type of the variable, EXPRESSION_TYPE_ERROR if there is no
variable

</dl>

<ul><a name="query_function_variable_type">
query_function_variable_type</a><pre>
int query_function_variable_type(string name)
</pre></br>
This method returns the type of the function variable.
<br/><ul>
<li><b>Parameters:</b>
<br/>name - the name of the function variable to check
<li><b>Returns:</b>
<br/>the type of the variable, EXPRESSION_TYPE_ERROR if there is no
variable

</dl>

<ul><a name="query_last_expression_error">
query_last_expression_error</a><pre>
string query_last_expression_error()
</pre></br>
This method returns the last error if there was an error in the parsing.
<br/><ul>
<li><b>Returns:</b>
<br/>the last error

</dl>

<ul><a name="query_last_expression_warning">
query_last_expression_warning</a><pre>
string query_last_expression_warning()
</pre></br>
This method returns the last warning if there was an warning in the parsing.
<br/><ul>
<li><b>Returns:</b>
<br/>the last warning

</dl>

<ul><a name="query_null_type">
query_null_type</a><pre>
class parse_node query_null_type(int type)
</pre></br>
This method returns a null object of the specified type.
<br/><ul>
<li><b>Parameters:</b>
<br/>type - the type to get the null object of
<li><b>Returns:</b>
<br/>the null object

</dl>

<ul><a name="query_operator_name">
query_operator_name</a><pre>
string query_operator_name(int operator)
</pre></br>
This method returns the string value of the operator name.
<br/><ul>
<li><b>Parameters:</b>
<br/>operator - the operator name to return
<li><b>Returns:</b>
<br/>the string name of the operator

</dl>

<ul><a name="query_type_name">
query_type_name</a><pre>
string query_type_name(int type)
</pre></br>
This method returns the name of the type.
<br/><ul>
<li><b>Parameters:</b>
<br/>type - the type to get the string name of
<li><b>Returns:</b>
<br/>the string name of the type

</dl>

<ul><a name="query_type_value">
query_type_value</a><pre>
int query_type_value(string type)
</pre></br>
This method returns the value of the type.
<br/><ul>
<li><b>Parameters:</b>
<br/>type - the type to get the integer value of
<li><b>Returns:</b>
<br/>the integer value of the type

</dl>

<ul><a name="query_user_function_arg_names">
query_user_function_arg_names</a><pre>
mixed * query_user_function_arg_names(string name)
</pre></br>
This method returns the argument names names of the user defined
function. 
<br/><ul>
<li><b>Parameters:</b>
<br/>name - the name of the function to lookup
<li><b>Returns:</b>
<br/>information on the arguments, 0 on failure

</dl>

<ul><a name="query_user_function_arg_types">
query_user_function_arg_types</a><pre>
mixed * query_user_function_arg_types(string name)
</pre></br>
This method returns the argument names types of the user defined
function. 
<br/><ul>
<li><b>Parameters:</b>
<br/>name - the name of the function to lookup
<li><b>Returns:</b>
<br/>information on the arguments, 0 on failure

</dl>

<ul><a name="query_user_function_args">
query_user_function_args</a><pre>
mixed * query_user_function_args(string name)
</pre></br>
This method returns the argument names and types of the user defined
function.  It returns an array of two elements, the first is an
array of names and the second is an array of types.
<br/><ul>
<li><b>Parameters:</b>
<br/>args - the arguments to return
<li><b>Returns:</b>
<br/>information on the arguments, 0 on failure

</dl>

<ul><a name="query_user_function_expression">
query_user_function_expression</a><pre>
class parse_node * query_user_function_expression(string name)
</pre></br>
This method returns the expression of the user defined function.
<br/><ul>
<li><b>Parameters:</b>
<br/>name - the name of the function to look up
<li><b>Returns:</b>
<br/>the expression of the user defined function

</dl>

<ul><a name="query_user_function_names">
query_user_function_names</a><pre>
string * query_user_function_names()
</pre></br>
This method returns the list of user defined functions in the
inheritable.
<br/><ul>
<li><b>Returns:</b>
<br/>the list of user defined functions

</dl>

<ul><a name="query_user_function_return_type">
query_user_function_return_type</a><pre>
int query_user_function_return_type(string name)
</pre></br>
This method returns the return type of the user defined function.
<br/><ul>
<li><b>Returns:</b>
<br/>the return type, EXPRESSION_TYPE_ERROR on error

</dl>

<ul><a name="query_user_function_string">
query_user_function_string</a><pre>
string query_user_function_string(string func)
</pre></br>
This method makes a nice string representation of the user function.
<br/><ul>
<li><b>Parameters:</b>
<br/>func - the name of the user function to get a string of
<li><b>Returns:</b>
<br/>the user function string

</dl>

<ul><a name="query_variable_names">
query_variable_names</a><pre>
string * query_variable_names()
</pre></br>
This method returns the names of all the variables.
<br/><ul>
<li><b>Returns:</b>
<br/>all the variable names

</dl>

<ul><a name="query_variable_type">
query_variable_type</a><pre>
int query_variable_type(string name)
</pre></br>
This method returns the type of the variable.
<br/><ul>
<li><b>Parameters:</b>
<br/>name - the name of the variable to check
<li><b>Returns:</b>
<br/>the type of the variable, EXPRESSION_TYPE_ERROR if there is no
variable

</dl>

<ul><a name="query_variable_value">
query_variable_value</a><pre>
function query_variable_value(string name)
</pre></br>
This method returns the value of the variable.
<br/><ul>
<li><b>Parameters:</b>
<br/>name - the name of the variable to find
<li><b>Returns:</b>
<br/>the value of the variable, 0 if not found

</dl>

<ul><a name="remove_user_expression">
remove_user_expression</a><pre>
int remove_user_expression(string name)
</pre></br>
This method removes the currently defined user expression.
<br/><ul>
<li><b>Parameters:</b>
<br/>name - the expression to remove

</dl>

<ul><a name="sizeof_function">
sizeof_function</a><pre>
int sizeof_function(mixed * arr,
                    mixed args ...)
</pre></br>
Does a sizeof an array.  Nifty...
<br/><ul>
<li><b>Parameters:</b>
<br/>arr - the array to get the sizeof
<br/>args - the rest of the arguments
<li><b>Returns:</b>
<br/>the sizeof the array

</dl>


<h2>Protected Functions</h2>
These are functions that only objects inheriting the class can access.<p>
<ul><a name="is_alpha">
is_alpha</a><pre>
int is_alpha(int alpha)
</pre></br>
This method checks to see if the passed in character is an alpha
or not.
<br/><ul>
<li><b>Parameters:</b>
<br/>alpha - the character to check
<li><b>Returns:</b>
<br/>1 if it alpha, 0 if not

</dl>

<ul><a name="is_array_type">
is_array_type</a><pre>
int is_array_type(int type)
</pre></br>
This checks to make sure that the type is an array.
<br/><ul>
<li><b>Parameters:</b>
<br/>type - the type to check
<li><b>Returns:</b>
<br/>1 if it is an array, 0 if not

</dl>

<ul><a name="is_null_array_type">
is_null_array_type</a><pre>
int is_null_array_type(int type)
</pre></br>
This checks to make sure that the type is a null array.
<br/><ul>
<li><b>Parameters:</b>
<br/>type - the type to check
<li><b>Returns:</b>
<br/>1 if it is a null array, 0 if not

</dl>

<ul><a name="is_number">
is_number</a><pre>
int is_number(int number)
</pre></br>
This method checks to see if the passed in character is a number
or not.
<br/><ul>
<li><b>Parameters:</b>
<br/>number - the character to check
<li><b>Returns:</b>
<br/>1 if it is a number, 0 if not

</dl>

<ul><a name="is_number_type">
is_number_type</a><pre>
int is_number_type(int type)
</pre></br>
This checks to make sure that the type is a number based type.
This can be controlled to make sure that any added types are also
allowed to be treated as numbers.
<br/><ul>
<li><b>Parameters:</b>
<br/>type - the type to check
<li><b>Returns:</b>
<br/>1 if it is a number, 0 if not

</dl>

<ul><a name="is_space">
is_space</a><pre>
int is_space(int space)
</pre></br>
This method checks to see if the passed in character is a space or
a space equivilant.
<br/><ul>
<li><b>Parameters:</b>
<br/>space - the character to check
<li><b>Returns:</b>
<br/>1 if it is a space, 0 if not

</dl>

<ul><a name="query_token">
query_token</a><pre>
string * query_token(string str)
</pre></br>
This method find the next token.  It can be overrideen in higher things
to deal with special token types (ie: money).
<br/><ul>
<li><b>Parameters:</b>
<br/>str - the input string
<li><b>Returns:</b>
<br/>({ token, rest })

</dl>


<h2>Classes</h2>
These are nice data types for dealing with...  Data!<p>
<ul>
<li><a name="class_func_variable_thing">
func_variable_thing</a><pre>
class func_variable_thing {
                            int type;
                            int arg_no;
}

</pre>
<li><a name="class_function_thing">
function_thing</a><pre>
class function_thing {
                       int type;
                       function value;
                       int * args;
                       int return_pos;
}

</pre>
<li><a name="class_user_function_thing">
user_function_thing</a><pre>
class user_function_thing {
                            int type;
                            class parse_node * expr;
                            int * arg_types;
                            string * arg_names;
}

</pre>
<li><a name="class_variable_thing">
variable_thing</a><pre>
class variable_thing {
                       int type;
                       function value;
}

</pre>
</ul>
[an error occurred while processing this directive]

