Home

[Package Index | Mudlib Index | Effect Index]

File /std/basic/expressions.c

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.

Written by Pinkfish

Started Thu May 4 22:44:34 PDT 2000

Includes

This class includes the following files /include/expressions.h, /include/shops/bank.h and /include/money.h

Class Index

Method index

Public Functions

These are functions that everyone can access.

.

    add_allowed_function
    void add_allowed_function(string name,
                              int type,
                              int * args,
                              function value)
    

    This method adds in an allowed function and specifies the types it takes.
    • Parameters:
      name - the name of the function
      type - the return type of the function
      args - the types of the arguements (an array)
      value - the function to call to get the value
    add_allowed_variable
    void add_allowed_variable(string name,
                              int type,
                              function value)
    

    This method adds in an allowed variable and specifies it's type.
    • Parameters:
      name - the name of the variable
      type - the type of the variable
      value - the value of the variable
        evaluate_expression
        class parse_node evaluate_expression(class parse_node * expr,
                                             mixed args ...)
        

        This method evaluates the expression and creates a nice end result thingy.
        • Parameters:
          expr - the exrpession to evaluate
          args - the optional args parsed into the various function calls
        • Returns:
          the type and value of the expression, 0 if failed
            parse_boolean_string
            class parse_node * parse_boolean_string(string str)
            

            A very small recursive decent parser which must return a boolean value.
            • Parameters:
              str - the input string
            • Returns:
              the array control structure
                parse_integer_string
                class parse_node * parse_integer_string(string str)
                

                A very small recursive decent parser which must return a integer value.
                • Parameters:
                  str - the input string
                • Returns:
                  the array control structure
                    parse_money_string
                    class parse_node * parse_money_string(string str)
                    

                    A very small recursive decent parser which must return a money value.
                    • Parameters:
                      str - the input string
                    • Returns:
                      the array control structure
                        parse_user_expression
                        string parse_user_expression(string def,
                                                     string str)
                        

                        This method attempts to parse a user expression.
                        • Parameters:
                          name - the name of the function
                          args - the name and types of the arguments
                          str - the input string
                        • Returns:
                          the name of the function, 0 on failure
                            parse_user_expression_definition
                            mixed * parse_user_expression_definition(string def)
                            

                            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.
                              query_expression_string
                              string query_expression_string(class parse_node * expr,
                                                             int brief)
                              

                              This method returns the expresion as a string.
                              • Parameters:
                                expr - the expression
                                brief - don't expand the variable names
                              • Returns:
                                the expression as a string
                                  query_function_args_types
                                  int * query_function_args_types(string name)
                                  

                                  This method returns the type of the function.
                                  • Parameters:
                                    name - the name of the function to check
                                  • Returns:
                                    the args of the function, null array is not found
                                      query_function_names
                                      string * query_function_names()
                                      

                                      This method returns all the function names defined in this expression inheritable.
                                      • Returns:
                                        the function names
                                          query_function_type
                                          int query_function_type(string name)
                                          

                                          This method returns the type of the function.
                                          • Parameters:
                                            name - the name of the function to check
                                          • Returns:
                                            the type of the function, EXPRESSION_TYPE_ERROR if there is no function
                                              query_function_value
                                              function query_function_value(string name)
                                              

                                              This method returns the value of the function.
                                              • Parameters:
                                                name - the name of the function to find
                                              • Returns:
                                                the value of the function, 0 if not found
                                                  query_function_variable_position
                                                  int query_function_variable_position(string name)
                                                  

                                                  This method returns the position of the function variable.
                                                  • Parameters:
                                                    name - the name of the function variable to check
                                                  • Returns:
                                                    the type of the variable, EXPRESSION_TYPE_ERROR if there is no variable
                                                      query_function_variable_type
                                                      int query_function_variable_type(string name)
                                                      

                                                      This method returns the type of the function variable.
                                                      • Parameters:
                                                        name - the name of the function variable to check
                                                      • Returns:
                                                        the type of the variable, EXPRESSION_TYPE_ERROR if there is no variable
                                                          query_last_expression_error
                                                          string query_last_expression_error()
                                                          

                                                          This method returns the last error if there was an error in the parsing.
                                                          • Returns:
                                                            the last error
                                                              query_last_expression_warning
                                                              string query_last_expression_warning()
                                                              

                                                              This method returns the last warning if there was an warning in the parsing.
                                                              • Returns:
                                                                the last warning
                                                                  query_null_type
                                                                  class parse_node query_null_type(int type)
                                                                  

                                                                  This method returns a null object of the specified type.
                                                                  • Parameters:
                                                                    type - the type to get the null object of
                                                                  • Returns:
                                                                    the null object
                                                                      query_operator_name
                                                                      string query_operator_name(int operator)
                                                                      

                                                                      This method returns the string value of the operator name.
                                                                      • Parameters:
                                                                        operator - the operator name to return
                                                                      • Returns:
                                                                        the string name of the operator
                                                                          query_type_name
                                                                          string query_type_name(int type)
                                                                          

                                                                          This method returns the name of the type.
                                                                          • Parameters:
                                                                            type - the type to get the string name of
                                                                          • Returns:
                                                                            the string name of the type
                                                                              query_type_value
                                                                              int query_type_value(string type)
                                                                              

                                                                              This method returns the value of the type.
                                                                              • Parameters:
                                                                                type - the type to get the integer value of
                                                                              • Returns:
                                                                                the integer value of the type
                                                                                  query_user_function_arg_names
                                                                                  mixed * query_user_function_arg_names(string name)
                                                                                  

                                                                                  This method returns the argument names names of the user defined function.
                                                                                  • Parameters:
                                                                                    name - the name of the function to lookup
                                                                                  • Returns:
                                                                                    information on the arguments, 0 on failure
                                                                                      query_user_function_arg_types
                                                                                      mixed * query_user_function_arg_types(string name)
                                                                                      

                                                                                      This method returns the argument names types of the user defined function.
                                                                                      • Parameters:
                                                                                        name - the name of the function to lookup
                                                                                      • Returns:
                                                                                        information on the arguments, 0 on failure
                                                                                          query_user_function_args
                                                                                          mixed * query_user_function_args(string name)
                                                                                          

                                                                                          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.
                                                                                          • Parameters:
                                                                                            args - the arguments to return
                                                                                          • Returns:
                                                                                            information on the arguments, 0 on failure
                                                                                              query_user_function_expression
                                                                                              class parse_node * query_user_function_expression(string name)
                                                                                              

                                                                                              This method returns the expression of the user defined function.
                                                                                              • Parameters:
                                                                                                name - the name of the function to look up
                                                                                              • Returns:
                                                                                                the expression of the user defined function
                                                                                                  query_user_function_names
                                                                                                  string * query_user_function_names()
                                                                                                  

                                                                                                  This method returns the list of user defined functions in the inheritable.
                                                                                                  • Returns:
                                                                                                    the list of user defined functions
                                                                                                      query_user_function_return_type
                                                                                                      int query_user_function_return_type(string name)
                                                                                                      

                                                                                                      This method returns the return type of the user defined function.
                                                                                                      • Returns:
                                                                                                        the return type, EXPRESSION_TYPE_ERROR on error
                                                                                                          query_user_function_string
                                                                                                          string query_user_function_string(string func)
                                                                                                          

                                                                                                          This method makes a nice string representation of the user function.
                                                                                                          • Parameters:
                                                                                                            func - the name of the user function to get a string of
                                                                                                          • Returns:
                                                                                                            the user function string
                                                                                                              query_variable_names
                                                                                                              string * query_variable_names()
                                                                                                              

                                                                                                              This method returns the names of all the variables.
                                                                                                              • Returns:
                                                                                                                all the variable names
                                                                                                                  query_variable_type
                                                                                                                  int query_variable_type(string name)
                                                                                                                  

                                                                                                                  This method returns the type of the variable.
                                                                                                                  • Parameters:
                                                                                                                    name - the name of the variable to check
                                                                                                                  • Returns:
                                                                                                                    the type of the variable, EXPRESSION_TYPE_ERROR if there is no variable
                                                                                                                      query_variable_value
                                                                                                                      function query_variable_value(string name)
                                                                                                                      

                                                                                                                      This method returns the value of the variable.
                                                                                                                      • Parameters:
                                                                                                                        name - the name of the variable to find
                                                                                                                      • Returns:
                                                                                                                        the value of the variable, 0 if not found
                                                                                                                          remove_user_expression
                                                                                                                          int remove_user_expression(string name)
                                                                                                                          

                                                                                                                          This method removes the currently defined user expression.
                                                                                                                          • Parameters:
                                                                                                                            name - the expression to remove
                                                                                                                              sizeof_function
                                                                                                                              int sizeof_function(mixed * arr,
                                                                                                                                                  mixed args ...)
                                                                                                                              

                                                                                                                              Does a sizeof an array. Nifty...
                                                                                                                              • Parameters:
                                                                                                                                arr - the array to get the sizeof
                                                                                                                                args - the rest of the arguments
                                                                                                                              • Returns:
                                                                                                                                the sizeof the array

                                                                                                                                Protected Functions

                                                                                                                                These are functions that only objects inheriting the class can access.

                                                                                                                                  is_alpha
                                                                                                                                  int is_alpha(int alpha)
                                                                                                                                  

                                                                                                                                  This method checks to see if the passed in character is an alpha or not.
                                                                                                                                  • Parameters:
                                                                                                                                    alpha - the character to check
                                                                                                                                  • Returns:
                                                                                                                                    1 if it alpha, 0 if not
                                                                                                                                      is_array_type
                                                                                                                                      int is_array_type(int type)
                                                                                                                                      

                                                                                                                                      This checks to make sure that the type is an array.
                                                                                                                                      • Parameters:
                                                                                                                                        type - the type to check
                                                                                                                                      • Returns:
                                                                                                                                        1 if it is an array, 0 if not
                                                                                                                                          is_null_array_type
                                                                                                                                          int is_null_array_type(int type)
                                                                                                                                          

                                                                                                                                          This checks to make sure that the type is a null array.
                                                                                                                                          • Parameters:
                                                                                                                                            type - the type to check
                                                                                                                                          • Returns:
                                                                                                                                            1 if it is a null array, 0 if not
                                                                                                                                              is_number
                                                                                                                                              int is_number(int number)
                                                                                                                                              

                                                                                                                                              This method checks to see if the passed in character is a number or not.
                                                                                                                                              • Parameters:
                                                                                                                                                number - the character to check
                                                                                                                                              • Returns:
                                                                                                                                                1 if it is a number, 0 if not
                                                                                                                                                  is_number_type
                                                                                                                                                  int is_number_type(int type)
                                                                                                                                                  

                                                                                                                                                  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.
                                                                                                                                                  • Parameters:
                                                                                                                                                    type - the type to check
                                                                                                                                                  • Returns:
                                                                                                                                                    1 if it is a number, 0 if not
                                                                                                                                                      is_space
                                                                                                                                                      int is_space(int space)
                                                                                                                                                      

                                                                                                                                                      This method checks to see if the passed in character is a space or a space equivilant.
                                                                                                                                                      • Parameters:
                                                                                                                                                        space - the character to check
                                                                                                                                                      • Returns:
                                                                                                                                                        1 if it is a space, 0 if not
                                                                                                                                                          query_token
                                                                                                                                                          string * query_token(string str)
                                                                                                                                                          

                                                                                                                                                          This method find the next token. It can be overrideen in higher things to deal with special token types (ie: money).
                                                                                                                                                          • Parameters:
                                                                                                                                                            str - the input string
                                                                                                                                                          • Returns:
                                                                                                                                                            ({ token, rest })

                                                                                                                                                            Classes

                                                                                                                                                            These are nice data types for dealing with... Data!

                                                                                                                                                            • func_variable_thing
                                                                                                                                                              class func_variable_thing {
                                                                                                                                                                                          int type;
                                                                                                                                                                                          int arg_no;
                                                                                                                                                              }
                                                                                                                                                              
                                                                                                                                                              
                                                                                                                                                            • function_thing
                                                                                                                                                              class function_thing {
                                                                                                                                                                                     int type;
                                                                                                                                                                                     function value;
                                                                                                                                                                                     int * args;
                                                                                                                                                                                     int return_pos;
                                                                                                                                                              }
                                                                                                                                                              
                                                                                                                                                              
                                                                                                                                                            • user_function_thing
                                                                                                                                                              class user_function_thing {
                                                                                                                                                                                          int type;
                                                                                                                                                                                          class parse_node * expr;
                                                                                                                                                                                          int * arg_types;
                                                                                                                                                                                          string * arg_names;
                                                                                                                                                              }
                                                                                                                                                              
                                                                                                                                                              
                                                                                                                                                            • variable_thing
                                                                                                                                                              class variable_thing {
                                                                                                                                                                                     int type;
                                                                                                                                                                                     function value;
                                                                                                                                                              }
                                                                                                                                                              
                                                                                                                                                              
Valid HTML 4.01 Transitional
Valid CSS!
Read More