/***********************************************************************************
 * Chaga string arithmetic library                                                 *
 * Copyright (C) 2026 Robert James Bruce                                           *
 *                                                                                 *
 * This file is part of the Chaga string arithmetic library.                       *
 *                                                                                 *
 * The Chaga string arithmetic library is free software: you can redistribute it   * 
 * and/or modify it under the terms of the GNU General Public License as published *
 * by the Free Software Foundation, either version 3 of the License, or (at your   *
 * option) any later version.                                                      *
 *                                                                                 *
 * The Chaga string arithmetic library is distributed in the hope that it will be  *
 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of          *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public *
 * License for more details.                                                       *
 *                                                                                 *
 * You should have received a copy of the GNU General Public License               *
 * along with the Chaga compiler. If not, see <https://www.gnu.org/licenses/>.     *
 ***********************************************************************************/
#include "include/libchaga-general_functions.h"
#include "include/libchaga-packed_string_integer_functions.h"
#include "include/libchaga-packed_string_float_functions.h"
#include "include/libchaga-boolean_functions.h"
#include "include/libchaga-diagnostic_tools.h"

digit_stack_node * push_digit_stack (digit_stack_node *digit_stack, unsigned char digit)
{
  digit_stack_node *new_element;
  unsigned char repacked_digits, nibble_lo, fourbit_digit;

  fourbit_digit = 0xf;
  switch (digit)
  {
    case '0':
    case '1':
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9':
      fourbit_digit = digit - '0';
    break;
    case '.':
      fourbit_digit = 0xa;
    break;
    case '+':
      fourbit_digit = 0xb;
    break;
    case '-':
      fourbit_digit = 0xc;
    break;
    default:
    break;
  }
  if ((fourbit_digit >= 0) && (fourbit_digit <= 0xc))
  {
    if (digit_stack != NULL) 
    {
      if ((digit_stack->stack_top_position >= 0) && (digit_stack->stack_top_position < MAX_DIGIT_STACK_BLOCK_SIZE))
      {
        if (digit_stack->stack_top_nibble_orientation == lo)
        {
          nibble_lo = digit_stack->digit[digit_stack->stack_top_position] & 0x0f;
          repacked_digits = (fourbit_digit << 4) + nibble_lo;
          digit_stack->digit[digit_stack->stack_top_position] = repacked_digits;
          digit_stack->stack_top_nibble_orientation = hi;
        }
        else
        {
          if (digit_stack->stack_top_nibble_orientation == hi)
          {
            if (digit_stack->stack_top_position + 1 < MAX_DIGIT_STACK_BLOCK_SIZE)
            {
              digit_stack->stack_top_position = digit_stack->stack_top_position + 1;
              digit_stack->digit[digit_stack->stack_top_position] = fourbit_digit;
              digit_stack->stack_top_nibble_orientation = lo;
            }
            else
            {
              new_element = (digit_stack_node *) malloc(sizeof(digit_stack_node));
              if (new_element != NULL)
              { 
                new_element->stack_top_position = 0;
                new_element->digit[0] = fourbit_digit;
                new_element->stack_top_nibble_orientation = lo;
                new_element->next = digit_stack;
                digit_stack = new_element;
              }
            }
          }
        }
      }
      else
      {
        new_element = (digit_stack_node *) malloc(sizeof(digit_stack_node));
        if (new_element != NULL)
        { 
          new_element->stack_top_position = 0;
          new_element->digit[0] = fourbit_digit;
          new_element->stack_top_nibble_orientation = lo;
          new_element->next = digit_stack;
          digit_stack = new_element;
        }
      }
    }
    else
    {
      new_element = (digit_stack_node *) malloc(sizeof(digit_stack_node));
      if (new_element != NULL)
      { 
        new_element->stack_top_position = 0;
        new_element->stack_top_nibble_orientation = lo;
        new_element->digit[0] = fourbit_digit;
        new_element->next = NULL;
        digit_stack = new_element;
      }
    }
  }
  return digit_stack;
}




digit_stack_node * pop_digit_stack (digit_stack_node *digit_stack)
{
  digit_stack_node *element;

  if (digit_stack != NULL)
  {
    if ((digit_stack->stack_top_position > 0) && (digit_stack->stack_top_position < MAX_DIGIT_STACK_BLOCK_SIZE))
    {
      if (digit_stack->stack_top_nibble_orientation == hi)
      {
        digit_stack->digit[digit_stack->stack_top_position] = digit_stack->digit[digit_stack->stack_top_position] & 0x0f; // erase the high nibble (pop).
        digit_stack->stack_top_nibble_orientation = lo;
      }
      else
      {
        if (digit_stack->stack_top_nibble_orientation == lo)
        {
          digit_stack->stack_top_position--;
          digit_stack->stack_top_nibble_orientation = hi;
        }
      }
    }
    else
    {
      if (digit_stack->stack_top_position == 0)
      {
        if (digit_stack->stack_top_nibble_orientation == hi)
        {
          digit_stack->digit[digit_stack->stack_top_position] = digit_stack->digit[digit_stack->stack_top_position] & 0x0f; // erase the high nibble (pop).
          digit_stack->stack_top_nibble_orientation = lo;
        }
        else
        {
          if (digit_stack->stack_top_nibble_orientation == lo)
          {
            element = digit_stack;
            digit_stack = digit_stack->next;
            free (element);
          } 
        }
      }
    }
  }
  return digit_stack;
}




unsigned char top_digit_stack (digit_stack_node *digit_stack)
{
  unsigned char byte, nibble;

  byte = 0; // NULL byte indicates an error occurred.
  if (digit_stack != NULL)
  {
    if ((digit_stack->stack_top_position >= 0) && (digit_stack->stack_top_position < MAX_DIGIT_STACK_BLOCK_SIZE))
    {
      if (digit_stack->stack_top_nibble_orientation == lo)
      {
        nibble = digit_stack->digit[digit_stack->stack_top_position] & 0x0f;
        switch (nibble)
        {
          case 0x0:
          case 0x1:
          case 0x2:
          case 0x3:
          case 0x4:
          case 0x5:
          case 0x6:
          case 0x7:
          case 0x8:
          case 0x9:
            byte = nibble + '0';
          break;
          case 0xa:
            byte = '.';
          break;
          case 0xb:
            byte = '+';
          break;
          case 0xc:
            byte = '-'; 
          break;
          default:
          break;
        }
      }
      else
      {
        if (digit_stack->stack_top_nibble_orientation == hi)
        {
          nibble = (digit_stack->digit[digit_stack->stack_top_position] & 0xf0) >> 4;
          switch (nibble)
          {
            case 0x0:
            case 0x1:
            case 0x2:
            case 0x3:
            case 0x4:
            case 0x5:
            case 0x6:
            case 0x7:
            case 0x8:
            case 0x9:
              byte = nibble + '0';
            break;
            case 0xa:
              byte = '.';
            break;
            case 0xb:
              byte = '+';
            break;
            case 0xc:
              byte = '-'; 
            break;
            default:
            break;
          }     
        }
      }
    }
  }
  return byte;
}




digit_queue_node * add_digit_queue (digit_queue_node *digit_queue, unsigned char digit)
{
  digit_queue_node *new_element, *temp_element;

  new_element = (digit_queue_node *) malloc(sizeof(digit_queue_node));
  if (new_element != NULL)
  {
    new_element->digit = digit;
    new_element->next = NULL;
  }
  if (digit_queue != NULL)
  {
    temp_element = digit_queue;
    while (temp_element->next != NULL)
    {
      temp_element = temp_element->next;
    }
    temp_element->next = new_element;
  }
  else
  {
    digit_queue = new_element;
  }
  return digit_queue;
}




digit_queue_node * free_digit_queue (digit_queue_node *digit_queue)
{
  digit_queue_node *temp_element;

  while (digit_queue != NULL)
  {
    temp_element = digit_queue;
    digit_queue = digit_queue->next;
    free (temp_element);
  }
  return digit_queue;
}




// ********************************************************************************************************
// * packed_string_component_release_memory                                                               *
// *                                                                                                      *
// * This function releases memory formerly allocated for a packed, string-based number component (psnc). *
// *                                                                                                      *
// * Input:  pointer to a string number                                                                   *
// * Output: NULL                                                                                         *
// ********************************************************************************************************
psnc * packed_string_number_component_release_memory (psnc *number_component)
{
  psnc *temp_number_component;

  while (number_component != NULL)
  {
    temp_number_component = number_component;
    number_component = number_component->next_number_block;
    free (temp_number_component);
    temp_number_component = NULL;
  }
  return number_component;
}




// ***************************************************************************************************
// * packed_string_number_component_copy_number                                                      *
// *                                                                                                 *
// * This function makes a duplicate copy of a packed string number component (psnc) data structure. *
// *                                                                                                 *
// * Input:  The string-based number component to copy.                                              *
// * Output: NULL on failure; pointer to a string-based number component (psnc) on success.          *
// ***************************************************************************************************
psnc * packed_string_number_component_copy_number (psnc *number_copy_head, psnc *number)
{
  psnc *new_number_block, *number_copy_previous, *temp_num;
  int state;
  unsigned char nibble_lo, packed_byte;
  long long int i;

// *************************************************************************
// * Release any previously used memory otherwise we'd have a memory leak. *
// *************************************************************************
  if (number_copy_head != NULL)
  {
    number_copy_head = packed_string_number_component_release_memory (number_copy_head);
  }
  if (number != NULL)
  {
    state = 0;
    temp_num = number;
    while (temp_num != NULL)
    {
      new_number_block = (psnc *) malloc(sizeof(psnc));
      if (new_number_block != NULL)
      {
        new_number_block->highest_digit_position  = temp_num->highest_digit_position;
        new_number_block->highest_nibble_position = temp_num->highest_nibble_position;
        new_number_block->first_number_block      = NULL;
        new_number_block->last_number_block       = NULL;
        new_number_block->previous_number_block   = NULL;
        new_number_block->next_number_block       = NULL;
        for (i = temp_num->highest_digit_position + 1; i < MAX_PACKED_NUMBER_BLOCK_SIZE; i++)
        {
          new_number_block->packed_number_block[i] = 0;
        }
        for (i = 0; i < temp_num->highest_digit_position; i++)
        {
          new_number_block->packed_number_block[i] = temp_num->packed_number_block[i];
        }
        if (temp_num->highest_nibble_position == hi)
        {
          new_number_block->packed_number_block[i] = temp_num->packed_number_block[i];
        }
        else
        {
          packed_byte = temp_num->packed_number_block[i];
          nibble_lo = packed_byte & 0x0f;
          new_number_block->packed_number_block[i] = nibble_lo;
        }
        switch (state)
        {
          case 0:
            number_copy_head = new_number_block;
            number_copy_head->first_number_block = new_number_block;
            number_copy_previous = NULL;
            state  = 10;
          break;
          case 10:
            if (number_copy_previous != NULL)
            {
              number_copy_previous->next_number_block = new_number_block;
            }
            new_number_block->first_number_block    = number_copy_head;
            new_number_block->previous_number_block = number_copy_previous; 
          break;
          default:
          break;
        }
        number_copy_previous = new_number_block;
      }
      temp_num = temp_num->next_number_block;
    }
    if (new_number_block != NULL)
    {
      temp_num = number_copy_head;
      while (temp_num != NULL)
      {
        temp_num->last_number_block = new_number_block;
        temp_num = temp_num->next_number_block;
      }
    }
  }
  return number_copy_head;
} 




// ***********************************************************
// * count_num_digits_in_packed_string_integer               *
// *                                                         *
// * This function returns the number of digits in a number. *
// *                                                         *
// * Input: a packed, string-based integer.                  *
// * Output: the number of digits in the input number.       *
// ***********************************************************
long long int count_num_digits_in_packed_string_integer (psint *number)
{
  psnc *temp_number_component;
  long long int number_of_digits;

  number_of_digits = 0;
  if (number != NULL)
  {
    if (number->left_of_decimal != NULL)
    {
      temp_number_component = number->left_of_decimal;
      while (temp_number_component != NULL)
      {
        if (temp_number_component->highest_nibble_position == hi)
        {
          number_of_digits = number_of_digits + (temp_number_component->highest_digit_position + 1) * 2; // memory starts at zero therefore add one. Two digits per byte.
        }         
        else
        {
          number_of_digits = number_of_digits + (temp_number_component->highest_digit_position + 1) * 2 - 1;
        }
        temp_number_component = temp_number_component->next_number_block;
      }
    }
  }
  return number_of_digits;
}




// ************************************************************************************************
// * add_psint_element_to_list                                                                    *
// *                                                                                              *
// * This function adds one packed, string-based integer (psint) to a linked list data structure. * 
// *                                                                                              *
// * Inputs: num1 (packed string-based integer) and num2 (packed string-based integer).           *
// * Output: a linked-list containing two packed, string-based integer elements.                  *
// ************************************************************************************************
psint_list_node * add_psint_element_to_list (psint_list_node *psint_list, psint *number)
{
  psint_list_node *new_element;
  psint *new_number;

  if (number != NULL)
  {
    new_element = (psint_list_node *) malloc(sizeof(psint_list_node));
    if (new_element != NULL)
    {
      new_number = NULL;
      new_number = packed_string_integer_copy_number (new_number, number);
      new_element->element = new_number;
      new_element->next_element = psint_list;
      psint_list = new_element;
    }
    else
    {
      printf ("Error in create_psint_list: malloc function returned NULL. Exiting now.\n");
      exit (EXIT_FAILURE);
    }
  }
  return psint_list;
}  





// *********************************************************************************************
// * create_two_element_psint_list                                                             *
// *                                                                                           *
// * This function creates a two-element packed, string-based integer (psint) linked list data * 
// * structure. It is useful interally to create a function return list with two string-based  *
// * integer parameters.                                                                       *
// *                                                                                           *
// * Inputs: num1 (packed string-based integer) and num2 (packed string-based integer).        *
// * Output: a linked-list containing two packed, string-based integer elements.               *
// *********************************************************************************************
psint_list_node * create_two_element_psint_list (psint *num1, psint *num2)
{
  psint_list_node *psint_list, *num1_element, *num2_element;

  psint_list = NULL;
  num1_element = NULL;
  num2_element = NULL;
  if ((num1 != NULL) && (num2 != NULL))
  {
    num2_element = (psint_list_node *) malloc(sizeof(psint_list_node));
    if (num2_element != NULL)
    {
      num2_element->element = num2;
      num2_element->next_element = NULL;
      num1_element = (psint_list_node *) malloc(sizeof(psint_list_node));
      if (num1_element != NULL)
      {
        num1_element->element = num1;
        num1_element->next_element = num2_element;
        psint_list = num1_element;
      }
      else
      {
        printf ("Error in create_two_element_psint_list(): malloc function returned NULL. Exiting now.\n");
        exit (EXIT_FAILURE);
      }
    }
    else
    {
      printf ("Error in create_two_element_psint_list(): malloc function returned NULL. Exiting now.\n");
      exit (EXIT_FAILURE);
    }
  }
  return psint_list;
}  




runtime_expression_node * push_operand_runtime_expression_stack (runtime_expression_node *runtime_expression_stack, chaga_operand_type operand_type, void *operand, unsigned char ok_to_free_memory_for_operand)
{
  runtime_expression_node *new_element, *temp_runtime_expression;

  if (operand != NULL)
  {
    new_element = (runtime_expression_node *) malloc(sizeof(runtime_expression_node));
    if (new_element != NULL)
    {
      new_element->operator = _none;   // to indicate this entry on stack is an OPERAND, not an OPERATOR.
      new_element->operand_type = operand_type;
      new_element->operand = NULL;
      new_element->ok_to_free_memory_for_operand = ok_to_free_memory_for_operand;
      switch (operand_type)
      {
        case _int:
          new_element->operand = operand;
        break;
        case _bool:
          new_element->operand = operand;
        break;
        case _float:
          new_element->operand = operand;
        break;
        case _constant_int:
          new_element->operand = operand;
        break;
        case _constant_float:
          new_element->operand = operand;
        break;
        case _constant_bool:
          new_element->operand = operand;
        break;
        default:
        break;
      }
      new_element->next = runtime_expression_stack;
      runtime_expression_stack = new_element;
    }
  }
  return runtime_expression_stack;
}




runtime_expression_node * pop_runtime_expression_stack (runtime_expression_node *runtime_expression_stack)
{
  runtime_expression_node *top_element;
  
  if (runtime_expression_stack != NULL)
  {
    top_element = runtime_expression_stack;
    runtime_expression_stack = runtime_expression_stack->next;
    free (top_element);
  }
  return runtime_expression_stack;
}




runtime_expression_node * add_operator_element_runtime_expression (runtime_expression_node *runtime_expression, chaga_operator_type operator)
{
  runtime_expression_node *new_element, *temp_runtime_expression;

  new_element = (runtime_expression_node *) malloc(sizeof(runtime_expression_node));
  if (new_element != NULL)
  {
    new_element->operator = operator;
    new_element->operand_type = _nothing; // to indicate this entry on stack is an OPERATOR, not an OPERAND
    new_element->operand = NULL;          // initialize pointer to non-existant operand as well.
    new_element->ok_to_free_memory_for_operand = FALSE;
    new_element->next = NULL;
    if (runtime_expression != NULL)
    {
      temp_runtime_expression = runtime_expression;
      while (temp_runtime_expression->next != NULL)
      {
        temp_runtime_expression = temp_runtime_expression->next;
      }
      temp_runtime_expression->next = new_element;
    }
    else
    {
      runtime_expression = new_element;
    }
  }
  return runtime_expression;
}




runtime_expression_node * add_operand_element_runtime_expression (runtime_expression_node *runtime_expression, chaga_operand_type operand_type, void *operand, unsigned char ok_to_free_memory_for_operand)
{
  runtime_expression_node *new_element, *temp_runtime_expression;

  if (operand != NULL)
  {
    new_element = (runtime_expression_node *) malloc(sizeof(runtime_expression_node));
    if (new_element != NULL)
    {
      new_element->operator = _none;   // to indicate this entry on stack is an OPERAND, not an OPERATOR.
      new_element->operand_type = operand_type;
      new_element->operand = NULL;
      new_element->ok_to_free_memory_for_operand = ok_to_free_memory_for_operand;
      switch (operand_type)
      {
        case _int:
          new_element->operand = operand;
        break;
        case _bool:
          new_element->operand = operand;
        break;
        case _float:
          new_element->operand = operand;
        break;
        case _constant_int:
          new_element->operand = operand;
        break;
        case _constant_float:
          new_element->operand = operand;
        break;
        case _constant_bool:
          new_element->operand = operand;
        break;
        default:
        break;
      }
      new_element->next = NULL;
      if (runtime_expression != NULL)
      {
        temp_runtime_expression = runtime_expression;
        while (temp_runtime_expression->next != NULL)
        {
          temp_runtime_expression = temp_runtime_expression->next;
        }
        temp_runtime_expression->next = new_element;
      }
      else
      {
        runtime_expression = new_element;
      }
    }
  }
  return runtime_expression;
}




// ********************************************************************************************
// * evaluate_runtime_expression_return_boolean_result                                        *
// *                                                                                          *
// * This subroutine evaluates an expression stack using Dijkstra's Shunting Yard algorithm.  *
// *                                                                                          *
// * The expression stack is comprised of the following in postfix order:                     *
// *       packed string float datatype (operand),                                            *
// *       packed string integer datatype (operand),                                          *
// *       Boolean datatype (operand),                                                        *
// *       plus (operator),                                                                   *
// *       minus (operator),                                                                  *
// *       times (operator),                                                                  *
// *       divide (operator),                                                                 *
// *       modulo (operator),                                                                 *
// *       and (operator),                                                                    *
// *       or (operator),                                                                     *
// *       not (operator)                                                                     *
// *                                                                                          *
// * This subroutine is called to evaluate Boolean expressions for the following statements:  *
// *       IF (BOOLEAN EXPRESSION) THEN                                                       *
// *       IF (BOOLEAN EXPRESSION) THEN-ELSE                                                  *
// *       DO-UNTIL (BOOLEAN EXPRESSION)                                                      *
// *       WHILE (BOOLEAN EXPRESSION)                                                         *
// *                                                                                          *
// * Note: the Boolean result is stored in temporary heap memory as is marked for deletion    *
// * (freeing the memory allocated for the temporary Boolean result on the heap) once one of  *
// * the statements above is evaluated.                                                       *
// *                                                                                          *
// * Return value: unsigned character return value containing either a 0 (FALSE) or 1 (TRUE). *
// ********************************************************************************************
unsigned char evaluate_runtime_expression_return_boolean_result (runtime_expression_node *expression_stack)
{
  psint *packed_string_integer1;
  psflt *packed_string_float1;
  unsigned char *bool_value1, *temp_bool_result, bool_result;
  unsigned char packed_string_integer1_is_a_temporary_variable;
  unsigned char packed_string_float1_is_a_temporary_variable;
  unsigned char bool_value1_is_a_temporary_variable;

  packed_string_integer1 = NULL;
  packed_string_float1   = NULL;
  bool_value1            = NULL;
  temp_bool_result       = NULL;
  bool_result = FALSE;
  if (expression_stack != NULL)
  {
    expression_stack = evaluate_runtime_expression (expression_stack);
    if (expression_stack != NULL)
    {
      if (expression_stack->operator == _none)
      {
        if (expression_stack->operand != NULL)
        {
          switch (expression_stack->operand_type)
          {
            case _constant_int:
              packed_string_integer1 = packed_string_integer_set_value (packed_string_integer1, (unsigned char *) expression_stack->operand);
              if (packed_string_integer1 != NULL)
              {
                temp_bool_result = convert_packed_string_integer_to_boolean (packed_string_integer1);
                if (temp_bool_result != NULL)
                {
                  bool_result = *temp_bool_result;
                }
                else
                {
                  bool_result = FALSE;
                }
                packed_string_integer1 = packed_string_integer_release_memory (packed_string_integer1);
              }
              expression_stack = pop_runtime_expression_stack (expression_stack);
            break;
            case _constant_float:
              packed_string_float1 = packed_string_float_set_value (packed_string_float1, (unsigned char *) expression_stack->operand);
              if (packed_string_float1 != NULL)
              {
                temp_bool_result = convert_packed_string_float_to_boolean (packed_string_float1);
                if (temp_bool_result != NULL)
                {
                  bool_result = *temp_bool_result;
                }
                else
                {
                  bool_result = FALSE;
                }
                packed_string_float1 = packed_string_float_release_memory (packed_string_float1);
              }
              expression_stack = pop_runtime_expression_stack (expression_stack);
            break;
            case _constant_bool:
              bool_value1 = (unsigned char *) expression_stack->operand;
              bool_value1_is_a_temporary_variable = expression_stack->ok_to_free_memory_for_operand;
              temp_bool_result = convert_boolean_string_to_boolean (bool_value1);
              if (temp_bool_result != NULL)
              {
                bool_result = *temp_bool_result;
              }
              else
              {
                bool_result = FALSE;
              }
              if (bool_value1_is_a_temporary_variable == TRUE)
              {
                free (bool_value1);
                bool_value1 = NULL;
              }
              expression_stack = pop_runtime_expression_stack (expression_stack);
            break;
            case _int:
              packed_string_integer1 = (psint *) expression_stack->operand;
              packed_string_integer1_is_a_temporary_variable = expression_stack->ok_to_free_memory_for_operand;
              temp_bool_result = convert_packed_string_integer_to_boolean (packed_string_integer1);
              if (temp_bool_result != NULL)
              {
                bool_result = *temp_bool_result;
              }
              else
              {
                bool_result = FALSE;
              }
              if (packed_string_integer1_is_a_temporary_variable == TRUE)
              {
                packed_string_integer1 = packed_string_integer_release_memory (packed_string_integer1);
              }
              expression_stack = pop_runtime_expression_stack (expression_stack);
            break;
            case _float:
              packed_string_float1 = (psflt *) expression_stack->operand;
              packed_string_float1_is_a_temporary_variable = expression_stack->ok_to_free_memory_for_operand;
              temp_bool_result = convert_packed_string_float_to_boolean (packed_string_float1);
              if (temp_bool_result != NULL)
              {
                bool_result = *temp_bool_result;
              }
              else
              {
                bool_result = FALSE;
              }
              if (packed_string_float1_is_a_temporary_variable == TRUE)
              {
                packed_string_float1 = packed_string_float_release_memory (packed_string_float1);
              }
              expression_stack = pop_runtime_expression_stack (expression_stack);
            break;
            case _bool:
              bool_value1 = (unsigned char *) expression_stack->operand;
              bool_value1_is_a_temporary_variable = expression_stack->ok_to_free_memory_for_operand;
              bool_result = *bool_value1;
              if (bool_value1_is_a_temporary_variable == TRUE)
              {
                free (bool_value1);
                bool_value1 = NULL;
              }
              expression_stack = pop_runtime_expression_stack (expression_stack);
            break;
            default:
            break;
          }
        }
      }
    }
  }
  if (expression_stack != NULL)
  {
    printf ("WARNING: expression_stack is NOT null but needs to be released.\n");
  }
  return bool_result;
}




psint * evaluate_runtime_expression_return_integer_result_for_set_statement (runtime_expression_node *expression_stack)
{
  psint *packed_string_integer1, *packed_string_integer_result;
  psflt *packed_string_float1;
  unsigned char *bool_value1;
  unsigned char packed_string_integer1_is_a_temporary_variable;
  unsigned char packed_string_float1_is_a_temporary_variable;
  unsigned char bool_value1_is_a_temporary_variable;

  packed_string_integer1 = NULL;
  packed_string_float1   = NULL;
  bool_value1            = NULL;
  packed_string_integer_result = NULL;
  if (expression_stack != NULL)
  {
    expression_stack = evaluate_runtime_expression (expression_stack);
    if (expression_stack != NULL)
    {
      if (expression_stack->operator == _none)
      {
        if (expression_stack->operand != NULL)
        {
          switch (expression_stack->operand_type)
          {
            case _constant_int:
              packed_string_integer1 = packed_string_integer_set_value (packed_string_integer_result, (unsigned char *) expression_stack->operand);
              packed_string_integer1_is_a_temporary_variable = expression_stack->ok_to_free_memory_for_operand;
              if (packed_string_integer1_is_a_temporary_variable == FALSE)
              {
                packed_string_integer_result = packed_string_integer_copy_number (packed_string_integer_result, packed_string_integer1);   
              }
              else
              {
                packed_string_integer1 = packed_string_integer_release_memory (packed_string_integer1);
              }
              expression_stack = pop_runtime_expression_stack (expression_stack);
            break;
            case _constant_float:
              packed_string_float1 = packed_string_float_set_value (packed_string_float1, (unsigned char *) expression_stack->operand);
              packed_string_float1_is_a_temporary_variable = expression_stack->ok_to_free_memory_for_operand;
              if (packed_string_float1 != NULL)
              {
                packed_string_integer_result = packed_string_float_truncate_to_packed_string_integer (packed_string_integer_result, packed_string_float1);
                if (packed_string_float1_is_a_temporary_variable == TRUE)
                {
                  packed_string_float1 = packed_string_float_release_memory (packed_string_float1);
                }
              }
              expression_stack = pop_runtime_expression_stack (expression_stack);
            break;
            case _constant_bool:
              bool_value1 = (unsigned char *) expression_stack->operand;
              bool_value1_is_a_temporary_variable = expression_stack->ok_to_free_memory_for_operand;
              if (bool_value1 != NULL)
              {
                packed_string_integer_result = convert_boolean_string_to_packed_string_integer (bool_value1);
                if (bool_value1_is_a_temporary_variable == TRUE)
                {
                  free (bool_value1);
                  bool_value1 = NULL;
                }
              }
              expression_stack = pop_runtime_expression_stack (expression_stack);
            break;
            case _int:
              packed_string_integer1 = (psint *) expression_stack->operand;
              packed_string_integer1_is_a_temporary_variable = expression_stack->ok_to_free_memory_for_operand;
              if (packed_string_integer1 != NULL)
              {
                packed_string_integer_result = packed_string_integer_copy_number (packed_string_integer_result, packed_string_integer1);   
                if (packed_string_integer1_is_a_temporary_variable == TRUE)
                {
                  packed_string_integer1 = packed_string_integer_release_memory (packed_string_integer1);
                }
              }
              expression_stack = pop_runtime_expression_stack (expression_stack);
            break;
            case _float:
              packed_string_float1 = (psflt *) expression_stack->operand;
              packed_string_float1_is_a_temporary_variable = expression_stack->ok_to_free_memory_for_operand;
              if (packed_string_float1 != NULL)
              {
                packed_string_integer_result = packed_string_float_truncate_to_packed_string_integer (packed_string_integer_result, packed_string_float1);
                if (packed_string_float1_is_a_temporary_variable == TRUE)
                {
                  packed_string_float1 = packed_string_float_release_memory (packed_string_float1);
                }
              }
              expression_stack = pop_runtime_expression_stack (expression_stack);
            break;
            case _bool:
              bool_value1 = (unsigned char *) expression_stack->operand;
              bool_value1_is_a_temporary_variable = expression_stack->ok_to_free_memory_for_operand;
              if (bool_value1 != NULL)
              {
                packed_string_integer_result = convert_boolean_to_packed_string_integer (bool_value1);
                if (bool_value1_is_a_temporary_variable == TRUE)
                {
                  free (bool_value1);
                  bool_value1 = NULL;
                }
              }
              expression_stack = pop_runtime_expression_stack (expression_stack);
            break;
            default:
            break;
          }
        }
      }
    }
  }
  if (expression_stack != NULL)
  {
    printf ("WARNING: expression_stack is NOT null but needs to be released.\n");
  }
  return packed_string_integer_result;
}
  
  


psflt * evaluate_runtime_expression_return_float_result_for_set_statement (runtime_expression_node *expression_stack)
{
  psint *packed_string_integer1;
  psflt *packed_string_float_result, *packed_string_float1;
  unsigned char *bool_value1;
  unsigned char packed_string_integer1_is_a_temporary_variable;
  unsigned char packed_string_float1_is_a_temporary_variable;
  unsigned char bool_value1_is_a_temporary_variable;

  packed_string_integer1 = NULL;
  packed_string_float1   = NULL;
  bool_value1            = NULL;
  packed_string_float_result = NULL;
  if (expression_stack != NULL)
  {
    expression_stack = evaluate_runtime_expression (expression_stack);
    if (expression_stack != NULL)
    {
      if (expression_stack->operator == _none)
      {
        if (expression_stack->operand != NULL)
        {
          switch (expression_stack->operand_type)
          {
            case _constant_int:
              packed_string_integer1 = packed_string_integer_set_value (packed_string_integer1, (unsigned char *) expression_stack->operand);
              packed_string_integer1_is_a_temporary_variable = expression_stack->ok_to_free_memory_for_operand;
              if (packed_string_integer1 != NULL)
              {
                packed_string_float_result = convert_packed_string_integer_to_packed_string_float (packed_string_float_result, packed_string_integer1);   
              }
              if (packed_string_integer1_is_a_temporary_variable == TRUE)
              {
                packed_string_integer1 = packed_string_integer_release_memory (packed_string_integer1);
              }
              expression_stack = pop_runtime_expression_stack (expression_stack);
            break;
            case _constant_float:
              packed_string_float_result = packed_string_float_set_value (packed_string_float_result, (unsigned char *) expression_stack->operand);
              expression_stack = pop_runtime_expression_stack (expression_stack);
            break;
            case _constant_bool:
              bool_value1 = (unsigned char *) expression_stack->operand;
              bool_value1_is_a_temporary_variable = expression_stack->ok_to_free_memory_for_operand;
              packed_string_float_result = convert_boolean_string_to_packed_string_float (bool_value1);
              if (bool_value1_is_a_temporary_variable == TRUE)
              {
                free (bool_value1);
                bool_value1 = NULL;
              }
              expression_stack = pop_runtime_expression_stack (expression_stack);
            break;
            case _int:
              packed_string_integer1 = (psint *) expression_stack->operand;
              packed_string_integer1_is_a_temporary_variable = expression_stack->ok_to_free_memory_for_operand;
              packed_string_float_result = convert_packed_string_integer_to_packed_string_float (packed_string_float_result, packed_string_integer1);   
              if (packed_string_integer1_is_a_temporary_variable == TRUE)
              {
                packed_string_integer1 = packed_string_integer_release_memory (packed_string_integer1);
              }
              expression_stack = pop_runtime_expression_stack (expression_stack);
            break;
            case _float:
              packed_string_float1 = (psflt *) expression_stack->operand;
              packed_string_float1_is_a_temporary_variable = expression_stack->ok_to_free_memory_for_operand;
              packed_string_float_result = packed_string_float_copy_number (packed_string_float_result, packed_string_float1);
              if (packed_string_float1_is_a_temporary_variable == TRUE)
              {
                packed_string_float1 = packed_string_float_release_memory (packed_string_float1);
              }
              expression_stack = pop_runtime_expression_stack (expression_stack);
            break;
            case _bool:
              bool_value1 = (unsigned char *) expression_stack->operand;
              bool_value1_is_a_temporary_variable = expression_stack->ok_to_free_memory_for_operand;
              packed_string_float_result = convert_boolean_to_packed_string_float (bool_value1);
              if (bool_value1_is_a_temporary_variable == TRUE)
              {
                free (bool_value1);
                bool_value1 = NULL;
              }
              expression_stack = pop_runtime_expression_stack (expression_stack);
            break;
            default:
            break;
          }
        }
      }
    }
  }
  if (expression_stack != NULL)
  {
    printf ("WARNING: expression_stack is NOT null but needs to be released.\n");
  }
  return packed_string_float_result;
}




unsigned char * evaluate_runtime_expression_return_boolean_result_for_set_statement (runtime_expression_node *expression_stack)
{
  psint *packed_string_integer1;
  psflt *packed_string_float1;
  unsigned char *bool_value1, *bool_result;
  unsigned char packed_string_integer1_is_a_temporary_variable;
  unsigned char packed_string_float1_is_a_temporary_variable;
  unsigned char bool_value1_is_a_temporary_variable;

  packed_string_integer1 = NULL;
  packed_string_float1   = NULL;
  bool_value1            = NULL;
  bool_result            = NULL;
  if (expression_stack != NULL)
  {
    expression_stack = evaluate_runtime_expression (expression_stack);
    if (expression_stack != NULL)
    {
      if (expression_stack->operator == _none)
      {
        if (expression_stack->operand != NULL)
        {
          switch (expression_stack->operand_type)
          {
            case _constant_int:
              packed_string_integer1 = packed_string_integer_set_value (packed_string_integer1, (unsigned char *) expression_stack->operand);
              if (packed_string_integer1 != NULL)
              {
                bool_result = convert_packed_string_integer_to_boolean (packed_string_integer1);
                packed_string_integer1 = packed_string_integer_release_memory (packed_string_integer1);
              }
              expression_stack = pop_runtime_expression_stack (expression_stack);
            break;
            case _constant_float:
              packed_string_float1 = packed_string_float_set_value (packed_string_float1, (unsigned char *) expression_stack->operand);
              if (packed_string_float1 != NULL)
              {
                bool_result = convert_packed_string_float_to_boolean (packed_string_float1);
                packed_string_float1 = packed_string_float_release_memory (packed_string_float1);
              }
              expression_stack = pop_runtime_expression_stack (expression_stack);
            break;
            case _constant_bool:
              bool_value1 = (unsigned char *) expression_stack->operand;
              bool_value1_is_a_temporary_variable = expression_stack->ok_to_free_memory_for_operand;
              bool_result = convert_boolean_string_to_boolean (bool_value1);
              if (bool_value1_is_a_temporary_variable == TRUE)
              {
                free (bool_value1);
                bool_value1 = NULL;
              }
              expression_stack = pop_runtime_expression_stack (expression_stack);
            break;
            case _int:
              packed_string_integer1 = (psint *) expression_stack->operand;
              packed_string_integer1_is_a_temporary_variable = expression_stack->ok_to_free_memory_for_operand;
              bool_result = convert_packed_string_integer_to_boolean (packed_string_integer1);
              if (packed_string_integer1_is_a_temporary_variable == TRUE)
              {
                packed_string_integer1 = packed_string_integer_release_memory (packed_string_integer1);
              }
              expression_stack = pop_runtime_expression_stack (expression_stack);
            break;
            case _float:
              packed_string_float1 = (psflt *) expression_stack->operand;
              packed_string_float1_is_a_temporary_variable = expression_stack->ok_to_free_memory_for_operand;
              bool_result = convert_packed_string_float_to_boolean (packed_string_float1);
              if (packed_string_float1_is_a_temporary_variable == TRUE)
              {
                packed_string_float1 = packed_string_float_release_memory (packed_string_float1);
              }
              expression_stack = pop_runtime_expression_stack (expression_stack);
            break;
            case _bool:
              bool_value1 = (unsigned char *) expression_stack->operand;
              bool_value1_is_a_temporary_variable = expression_stack->ok_to_free_memory_for_operand;
              bool_result = (unsigned char *) malloc(sizeof(unsigned char));
              if (bool_result != NULL)
              {
                *bool_result = *bool_value1;
              }
              if (bool_value1_is_a_temporary_variable == TRUE)
              {
                free (bool_value1);
                bool_value1 = NULL;
              }
              expression_stack = pop_runtime_expression_stack (expression_stack);
            break;
            default:
            break;
          }
        }
      }
    }
  }
  if (expression_stack != NULL)
  {
    printf ("WARNING: expression_stack is NOT null but needs to be released.\n");
  }
  return bool_result;
}




// *****************************************************************************************************************
// * evaluate_runtime_expression:                                                                                  *    
// *                                                                                                               *
// * This subroutine is the real evaluator for all Boolean or mixed Boolean-numerical expression evaluation using  *
// * Dijkstra's Shunting Yard algorithm to evaluate expressions in postfix notation on an input expression stack.  *
// *                                                                                                               *
// * Upon success, the expression stack and a temporary expression stack are returned. Under normal circumstances, *
// * the expression stack will be NULL (empty) and the temporary expression stack will contain one element - the   *
// * result of the expression. It is up to the calling function to convert that result into whatever the target    *
// * datatype requires. For example, integer datatypes must convert float or Boolean results into an integer.      *
// *****************************************************************************************************************
runtime_expression_node * evaluate_runtime_expression (runtime_expression_node *expression_stack)
{
  runtime_expression_node *expression_stack_list, *expression_stack_list_element, *temp_expression_stack;
  psint *packed_string_integer1, *packed_string_integer2, *packed_string_integer3, *packed_string_integer_result;
  psflt *packed_string_float1, *packed_string_float2, *packed_string_float3;
  unsigned char *bool_value1, *bool_value2, *bool_value3;
  unsigned char *constant_integer1, *constant_integer2, *constant_float1, *constant_float2, *constant_boolean1, *constant_boolean2;
  unsigned char packed_string_integer1_is_a_temporary_variable, packed_string_integer2_is_a_temporary_variable, packed_string_integer3_is_a_temporary_variable;
  unsigned char packed_string_float1_is_a_temporary_variable, packed_string_float2_is_a_temporary_variable, packed_string_float3_is_a_temporary_variable;
  unsigned char bool_value1_is_a_temporary_variable, bool_value2_is_a_temporary_variable, bool_value3_is_a_temporary_variable;
  unsigned char constant_integer1_is_a_temporary_variable, constant_integer2_is_a_temporary_variable, constant_float1_is_a_temporary_variable, constant_float2_is_a_temporary_variable;
  unsigned char constant_boolean1_is_a_temporary_variable, constant_boolean2_is_a_temporary_variable;
  chaga_operator_type operator;
  chaga_operand_type  operand;
  int state;
  size_t string_length;

  packed_string_integer1 = NULL;
  packed_string_integer2 = NULL;
  packed_string_integer3 = NULL;
  packed_string_float1   = NULL;
  packed_string_float2   = NULL;
  packed_string_float3   = NULL;
  bool_value1            = NULL;
  bool_value2            = NULL;
  bool_value3            = NULL;
  temp_expression_stack  = NULL;
  constant_integer1      = NULL;
  constant_integer2      = NULL;
  constant_float1        = NULL;
  constant_float2        = NULL;
  constant_boolean1      = NULL;
  constant_boolean2      = NULL;
  expression_stack_list        = NULL;
  packed_string_integer_result = NULL;
  state = 0;
  while (state < 999)
  {
    //printf ("\n\nstate = %d\n", state);
    //printf ("EXPRESSION STACK:\n");
    //display_runtime_expression_stack (expression_stack);
    //printf ("\n");
    //printf ("TEMP EXPRESSION STACK:\n");
    //display_runtime_expression_stack (temp_expression_stack);
    //printf ("\n");
    switch (state)
    {
      case 0:
        if (expression_stack != NULL)
        {
          if (expression_stack->operator == _none)
          {
            if (expression_stack->operand != NULL)
            {
              switch (expression_stack->operand_type)
              {
                case _int:
                case _float:
                case _bool:
                case _constant_int:
                case _constant_float:
                case _constant_bool:
                  temp_expression_stack = push_operand_runtime_expression_stack (temp_expression_stack, expression_stack->operand_type, (void *) expression_stack->operand, expression_stack->ok_to_free_memory_for_operand);
		  expression_stack = pop_runtime_expression_stack (expression_stack);
                  state = 0;
                break;
                default:
                  printf ("ERROR: Unknown operand\n");
                  state = 999;
                break;
              }
            }
            else
            {
              printf ("ERROR: expression_stack->operand is NULL\n");
              state = 999;
            }
          }
          else
          {
            if (temp_expression_stack != NULL)
            {
              state = 30; 
            }
            else
            {
              //printf ("ERROR: Expected operand but none exist on expression_stack and temp_expression_stack.\n");
              state = 999;
            }
          }
        } 
        else
        {
          //printf ("Expression stack is NULL. Setting state to 1000.\n");
          state = 1000;
        }
      break;
// ************************************************
// * STATE 10: Expecting second operand on stack. *
// ************************************************
      case 10: 
        printf ("In state 10 but should not be here.\n");
        exit (EXIT_FAILURE);
      break;
      case 20: 
        printf ("In state 20 but should not be here.\n");
        exit (EXIT_FAILURE);
      break;
      case 30:
        operator               = _none;
        operand                = _nothing;
        packed_string_integer1 = NULL;
        packed_string_float1   = NULL;
        packed_string_integer2 = NULL;
        packed_string_float2   = NULL;
        packed_string_integer3 = NULL;
        packed_string_float3   = NULL;
        bool_value1            = NULL;
        bool_value2            = NULL;
        bool_value3            = NULL;
        constant_integer1      = NULL;
        constant_integer2      = NULL;
        constant_float1        = NULL;
        constant_float2        = NULL;
        constant_boolean1      = NULL;
        constant_boolean2      = NULL;
        constant_integer1_is_a_temporary_variable      = FALSE;
        constant_integer2_is_a_temporary_variable      = FALSE;
        constant_float1_is_a_temporary_variable        = FALSE;
        constant_float2_is_a_temporary_variable        = FALSE;
        packed_string_integer1_is_a_temporary_variable = FALSE;
        packed_string_integer2_is_a_temporary_variable = FALSE;
        packed_string_integer3_is_a_temporary_variable = FALSE;
        packed_string_float1_is_a_temporary_variable   = FALSE;
        packed_string_float2_is_a_temporary_variable   = FALSE;
        packed_string_float3_is_a_temporary_variable   = FALSE;
        bool_value1_is_a_temporary_variable            = FALSE;
        bool_value2_is_a_temporary_variable            = FALSE;
        bool_value3_is_a_temporary_variable            = FALSE;
        if (expression_stack != NULL)
        {
          if (expression_stack->operator != _none)
          {
            operator = expression_stack->operator;
            switch (operator)
            {
// *********************************************************************************************************************
// * For the following operands: GREATER THAN OR EQUAL, GREATER THAN, LESS THAN OR EQUAL, LESS THAN, NOT EQUAL, EQUAL: *
// * both operands must be converted to INTEGER or FLOAT datatype.                                                     *
// *********************************************************************************************************************
              case _greater_than_or_equal:
              case _greater_than:
              case _less_than_or_equal:
              case _less_than:
              case _not_equal:
              case _equal:
                expression_stack = pop_runtime_expression_stack (expression_stack);
                if (temp_expression_stack != NULL)
                {
                  if (temp_expression_stack->operator == _none)
                  {
                    if (temp_expression_stack->operand != NULL)
                    {
                      switch (temp_expression_stack->operand_type)
                      {
                        case _int:
                          packed_string_integer2 = (psint *) temp_expression_stack->operand;
                          packed_string_integer2_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                          temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                        break;
                        case _float:
                          packed_string_float2 = (psflt *) temp_expression_stack->operand;
                          packed_string_float2_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                          temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                        break;
                        case _bool:
                          bool_value2 = (unsigned char *) temp_expression_stack->operand;
                          bool_value2_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                          temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                        break;
                        case _constant_int:
                          string_length = strlen ((unsigned char *) temp_expression_stack->operand) + 1;
                          if (string_length > 1)
                          {
                            constant_integer2 = (unsigned char *) malloc(sizeof(unsigned char) * string_length);
                            if (constant_integer2 != NULL)
                            {
                              strncpy (constant_integer2, (unsigned char *) temp_expression_stack->operand, string_length);
                              constant_integer2_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                              temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                            }
                            else
                            {
                              state = 999;
                            }
                          }
                        break;
                        case _constant_float:
                          string_length = strlen ((unsigned char *) temp_expression_stack->operand) + 1;
                          if (string_length > 1)
                          {
                            constant_float2 = (unsigned char *) malloc(sizeof(unsigned char) * string_length);
                            if (constant_float2 != NULL)
                            {
                              strncpy (constant_float2, (unsigned char *) temp_expression_stack->operand, string_length);
                              constant_float2_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                              temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                            }
                            else
                            {
                              state = 999;
                            }
                          }
                        break;
                        case _constant_bool:
                          constant_boolean2 = (unsigned char *) temp_expression_stack->operand;
                          constant_boolean2_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                          temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                        break;
                        default:
                          printf ("ERROR: Unknown operand\n");
                          state = 999;
                        break;
                      }
                    }
                  }
                }
                if (temp_expression_stack != NULL)
                {
                  if (temp_expression_stack->operator == _none)
                  {
                    if (temp_expression_stack->operand != NULL)
                    {
                      switch (temp_expression_stack->operand_type)
                      {
                        case _int:
                          packed_string_integer1 = (psint *) temp_expression_stack->operand;
                          packed_string_integer1_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                          temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                        break;
                        case _float:
                          packed_string_float1 = (psflt *) temp_expression_stack->operand;
                          packed_string_float1_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                          temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                        break;
                        case _bool:
                          bool_value1 = (unsigned char *) temp_expression_stack->operand;
                          bool_value1_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                          temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                        break;
                        case _constant_int:
                          string_length = strlen ((unsigned char *) temp_expression_stack->operand) + 1;
                          if (string_length > 1)
                          {
                            constant_integer1 = (unsigned char *) malloc(sizeof(unsigned char) * string_length);
                            if (constant_integer1 != NULL)
                            {
                              strncpy (constant_integer1, (unsigned char *) temp_expression_stack->operand, string_length);
                              constant_integer1_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                              temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                            }
                            else
                            {
                              state = 999;
                            }
                          }
                        break;
                        case _constant_float:
                          string_length = strlen ((unsigned char *) temp_expression_stack->operand) + 1;
                          if (string_length > 1)
                          {
                            constant_float1 = (unsigned char *) malloc(sizeof(unsigned char) * string_length);
                            if (constant_float1 != NULL)
                            {
                              strncpy (constant_float1, (unsigned char *) temp_expression_stack->operand, string_length);
                              constant_float1_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                              temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                            }
                            else
                            {
                              state = 999;
                            }
                          }
                        break;
                        case _constant_bool:
                          constant_boolean1 = (unsigned char *) temp_expression_stack->operand;
                          constant_boolean1_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                          temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                        break;
                        default:
                          printf ("ERROR: Unknown operand\n");
                          state = 999;
                        break;
                      }
                    }
                  }
                }
// ******************************************************************************************************************************************
// * Convert both operand1 and operand2 to either integer datatype or float datatype before performing the GREATER THAN OR EQUAL operation. *
// ******************************************************************************************************************************************
                if (state < 999)
                {
                  if (constant_integer1 != NULL)
                  {
                    if (constant_integer2 != NULL)
                    {
                      packed_string_integer1 = packed_string_integer_set_value (packed_string_integer1, constant_integer1);
                      packed_string_integer1_is_a_temporary_variable = TRUE;
                      packed_string_integer2 = packed_string_integer_set_value (packed_string_integer2, constant_integer2);
                      packed_string_integer2_is_a_temporary_variable = TRUE;
                    }
                    else
                    {
                      if (constant_float2 != NULL)
                      {
                        packed_string_float1 = packed_string_float_set_value (packed_string_float1, constant_integer1);
                        packed_string_float1_is_a_temporary_variable = TRUE;
                        packed_string_float2 = packed_string_float_set_value (packed_string_float2, constant_float2);
                        packed_string_float2_is_a_temporary_variable = TRUE;
                      }
                      else
                      {
                        if (constant_boolean2 != NULL)
                        {
                          packed_string_integer1 = packed_string_integer_set_value (packed_string_integer1, constant_integer1);
                          packed_string_integer1_is_a_temporary_variable = TRUE;
                          packed_string_integer2 = convert_boolean_string_to_packed_string_integer (constant_boolean2);
                          packed_string_integer2_is_a_temporary_variable = TRUE;
                        }
                        else
                        {
                          if (packed_string_integer2 != NULL)
                          {
                            packed_string_integer1 = packed_string_integer_set_value (packed_string_integer1, constant_integer1);
                            packed_string_integer1_is_a_temporary_variable = TRUE;
                          }
                          else
                          {
                            if (packed_string_float2 != NULL)
                            {
                              packed_string_float1 = packed_string_float_set_value (packed_string_float1, constant_integer1);
                              packed_string_float1_is_a_temporary_variable = TRUE;
                            }
                            else
                            {
                              if (bool_value2 != NULL)
                              {
                                packed_string_integer1 = packed_string_integer_set_value (packed_string_integer1, constant_integer1);
                                packed_string_integer1_is_a_temporary_variable = TRUE;
                                packed_string_integer2 = convert_boolean_to_packed_string_integer (bool_value2);
                                packed_string_integer2_is_a_temporary_variable = TRUE;
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                  else
                  {
                    if (constant_float1 != NULL)
                    {
                      packed_string_float1 = packed_string_float_set_value (packed_string_float1, constant_float1);
                      packed_string_float1_is_a_temporary_variable = TRUE;
                      if (constant_float2 != NULL)
                      {
                        packed_string_float2 = packed_string_float_set_value (packed_string_float2, constant_float2);
                        packed_string_float2_is_a_temporary_variable = TRUE;
                      }
                      else
                      {
                        if (constant_integer2 != NULL)
                        {
                          packed_string_float2 = packed_string_float_set_value (packed_string_float2, constant_integer2);
                          packed_string_float2_is_a_temporary_variable = TRUE;
                        }
                        else
                        {
                          if (constant_boolean2 != NULL)
                          {
                            packed_string_float2 = convert_boolean_string_to_packed_string_float (constant_boolean2);
                            packed_string_float2_is_a_temporary_variable = TRUE;
                          }
                          else
                          {
                            if (packed_string_integer2 != NULL)
                            {
                              packed_string_float2 = convert_packed_string_integer_to_packed_string_float (packed_string_float2, packed_string_integer2); 
                              packed_string_float2_is_a_temporary_variable = TRUE;
                            }
                            else
                            {
                              if (bool_value2 != NULL)
                              {
                                packed_string_float2 = convert_boolean_to_packed_string_float (bool_value2);
                                packed_string_float2_is_a_temporary_variable = TRUE;
                              }
                            }
                          }
                        }
                      }
                    }
                    else
                    {
                      if (packed_string_integer1 != NULL)
                      {
                        if (constant_integer2 != NULL)
                        {
                          packed_string_integer2 = packed_string_integer_set_value (packed_string_integer2, constant_integer2);
                          packed_string_integer2_is_a_temporary_variable = TRUE;
                        }
                        else
                        {
                          if (constant_float2 != NULL)
                          {
                            packed_string_float1 = convert_packed_string_integer_to_packed_string_float (packed_string_float1, packed_string_integer1); 
                            packed_string_float1_is_a_temporary_variable = TRUE;
                            packed_string_float2 = packed_string_float_set_value (packed_string_float2, constant_float2);
                            packed_string_float2_is_a_temporary_variable = TRUE;
                          }
                          else
                          {
                            if (constant_boolean2 != NULL)
                            {
                              packed_string_integer2 = convert_boolean_string_to_packed_string_integer (constant_boolean2);
                              packed_string_integer2_is_a_temporary_variable = TRUE;
                            }
                            else
                            {
                              if (packed_string_float2 != NULL)
                              {
                                packed_string_float1 = convert_packed_string_integer_to_packed_string_float (packed_string_float1, packed_string_integer1); 
                                packed_string_float1_is_a_temporary_variable = TRUE;
                              }
                              else
                              {
                                if (bool_value2 != NULL)
                                {
                                  packed_string_integer2 = convert_boolean_to_packed_string_integer (bool_value2);
                                  packed_string_integer2_is_a_temporary_variable = TRUE;
                                }
                              }
                            }
                          }
                        }
                      }
                      else
                      {
                        if (packed_string_float1 != NULL)
                        {
                          if (constant_integer2 != NULL)
                          {
                            packed_string_float2 = packed_string_float_set_value (packed_string_float2, constant_integer2);
                            packed_string_float2_is_a_temporary_variable = TRUE;
                          }
                          else
                          {
                            if (constant_boolean2 != NULL)
                            {
                              packed_string_float2 = convert_boolean_string_to_packed_string_float (constant_boolean2);
                              packed_string_float2_is_a_temporary_variable = TRUE;
                            }
                            else
                            {
                              if (constant_float2 != NULL)
                              {
                                packed_string_float2 = packed_string_float_set_value (packed_string_float2, constant_float2);
                                packed_string_float2_is_a_temporary_variable = TRUE;
                              }
                              else
                              {
                                if (packed_string_integer2 != NULL)
                                {
                                  packed_string_float2 = convert_packed_string_integer_to_packed_string_float (packed_string_float2, packed_string_integer2); 
                                  packed_string_float2_is_a_temporary_variable = TRUE;
                                }
                                else
                                {
                                  if (bool_value2 != NULL)
                                  {
                                    packed_string_float2 = convert_boolean_to_packed_string_float (bool_value2);
                                    packed_string_float2_is_a_temporary_variable = TRUE;
                                  }
                                }
                              }
                            }
                          }
                        }
                        else
                        {
                          if (constant_boolean1 != NULL)
                          {
                            if (constant_boolean2 != NULL)
                            {
                              packed_string_integer1 = convert_boolean_string_to_packed_string_integer (constant_boolean1);
                              packed_string_integer1_is_a_temporary_variable = TRUE;
                              packed_string_integer2 = convert_boolean_string_to_packed_string_integer (constant_boolean2);
                              packed_string_integer2_is_a_temporary_variable = TRUE;
                            }
                            else
                            {
                              if (constant_integer2 != NULL)
                              {
                                packed_string_integer1 = convert_boolean_string_to_packed_string_integer (constant_boolean1);
                                packed_string_integer1_is_a_temporary_variable = TRUE;
                                packed_string_integer2 = packed_string_integer_set_value (packed_string_integer2, constant_integer2);
                                packed_string_integer2_is_a_temporary_variable = TRUE;
                              }
                              else
                              {
                                if (constant_float2 != NULL)
                                {
                                  packed_string_float1 = convert_boolean_string_to_packed_string_float (constant_boolean1);
                                  packed_string_float1_is_a_temporary_variable = TRUE;
                                  packed_string_float2 = packed_string_float_set_value (packed_string_float2, constant_float2);
                                  packed_string_float2_is_a_temporary_variable = TRUE;
                                }
                                else
                                {
                                  if (packed_string_integer2 != NULL)
                                  {
                                    packed_string_integer1 = convert_boolean_string_to_packed_string_integer (constant_boolean1);
                                    packed_string_integer1_is_a_temporary_variable = TRUE;
                                  }
                                  else
                                  {
                                    if (packed_string_float2 != NULL)
                                    {
                                      packed_string_float1 = convert_boolean_string_to_packed_string_float (constant_boolean1);
                                      packed_string_float1_is_a_temporary_variable = TRUE;
                                    }
                                  }
                                }
                              }
                            }
                          }
                          else
                          {
                            if (bool_value1 != NULL)
                            {
                              if (constant_boolean2 != NULL)
                              {
                                packed_string_integer1 = convert_boolean_to_packed_string_integer (bool_value1);
                                packed_string_integer1_is_a_temporary_variable = TRUE;
                                packed_string_integer2 = convert_boolean_string_to_packed_string_integer (constant_boolean2);
                                packed_string_integer2_is_a_temporary_variable = TRUE;
                              }
                              else
                              {
                                if (constant_integer2 != NULL)
                                {
                                  packed_string_integer1 = convert_boolean_to_packed_string_integer (bool_value1);
                                  packed_string_integer1_is_a_temporary_variable = TRUE;
                                  packed_string_integer2 = packed_string_integer_set_value (packed_string_integer2, constant_integer2);
                                  packed_string_integer2_is_a_temporary_variable = TRUE;
                                }
                                else
                                {
                                  if (constant_float2 != NULL)
                                  {
                                    packed_string_float1 = convert_boolean_to_packed_string_float (bool_value1);
                                    packed_string_float1_is_a_temporary_variable = TRUE;
                                    packed_string_float2 = packed_string_float_set_value (packed_string_float2, constant_float2);
                                    packed_string_float2_is_a_temporary_variable = TRUE;
                                  }
                                  else
                                  {
                                    if (bool_value2 != NULL)
                                    {
                                      packed_string_integer1 = convert_boolean_to_packed_string_integer (bool_value1);
                                      packed_string_integer1_is_a_temporary_variable = TRUE;
                                      packed_string_integer2 = convert_boolean_to_packed_string_integer (bool_value2);
                                      packed_string_integer2_is_a_temporary_variable = TRUE;
                                    }
                                    else
                                    {                        
                                      if (packed_string_integer2 != NULL)
                                      {
                                        packed_string_integer1 = convert_boolean_to_packed_string_integer (bool_value1);
                                        packed_string_integer1_is_a_temporary_variable = TRUE;
                                      }
                                      else
                                      {
                                        if (packed_string_float2 != NULL)
                                        {
                                          packed_string_float1 = convert_boolean_to_packed_string_float (bool_value1);
                                          packed_string_float1_is_a_temporary_variable = TRUE;
                                        }
                                      }
                                    }
                                  }
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                  switch (operator)
                  {
                    case _greater_than_or_equal:
// ************************************************
// * Perform the GREATER THAN OR EQUAL operation. *
// ************************************************
                      if ((packed_string_integer1 != NULL) && (packed_string_integer2 != NULL))
                      {
                        bool_value3 = (unsigned char *) malloc(sizeof(unsigned char));
                        bool_value3_is_a_temporary_variable = FALSE; // mark as FALSE because copy of pointer is on the stack. IF we release memory immediately, stack will point to empty free'd value.
                        if (bool_value3 != NULL)
                        {
                          *bool_value3 = packed_string_integer_greater_than_or_equal (packed_string_integer1, packed_string_integer2);
                          switch (*bool_value3)
                          {
                            case 0:
                            case 1:
                              temp_expression_stack = push_operand_runtime_expression_stack (temp_expression_stack, _bool, bool_value3, TRUE);
                              state = 40;
                            break;
                            default:
                              printf ("ERROR: packed_string_integer_greater_than_or_equal returned unknown value.\n");
                              state = 999;
                            break;
                          }
                        }
                        else
                        {
                          printf ("ERROR: malloc failed.\n");
                          state = 999;
                        }
                      }
                      else
                      {
                        if ((packed_string_float1 != NULL) && (packed_string_float2 != NULL))
                        {
                          bool_value3 = (unsigned char *) malloc(sizeof(unsigned char));
                          bool_value3_is_a_temporary_variable = FALSE; // mark as FALSE because copy of pointer is on the stack. IF we release memory immediately, stack will point to empty free'd value.
                          if (bool_value3 != NULL)
                          {
                            *bool_value3 = packed_string_float_greater_than_or_equal (packed_string_float1, packed_string_float2);
                            switch (*bool_value3)
                            {
                              case 0:
                              case 1:
                                temp_expression_stack = push_operand_runtime_expression_stack (temp_expression_stack, _bool, bool_value3, TRUE);
                                state = 40;
                              break;
                              default:
                                printf ("ERROR: packed_string_integer_greater_than_or_equal returned unknown value.\n");
                                state = 999;
                              break;
                            }
                          }
                          else
                          {
                            printf ("ERROR: malloc failed.\n");
                            state = 999;
                          }
                        }
                        else
                        {
                          printf ("ERROR: datatype mismatch.\n");
                          state = 999;
                        }
                      }
                    break;
                    case _greater_than:
// ***************************************
// * Perform the GREATER THAN operation. *
// ***************************************
                      if ((packed_string_integer1 != NULL) && (packed_string_integer2 != NULL))
                      {
                        bool_value3 = (unsigned char *) malloc(sizeof(unsigned char));
                        bool_value3_is_a_temporary_variable = FALSE; // mark as FALSE because copy of pointer is on the stack. IF we release memory immediately, stack will point to empty free'd value.
                        if (bool_value3 != NULL)
                        {
                          *bool_value3 = packed_string_integer_greater_than (packed_string_integer1, packed_string_integer2);
                          switch (*bool_value3)
                          {
                            case 0:
                            case 1:
                              temp_expression_stack = push_operand_runtime_expression_stack (temp_expression_stack, _bool, bool_value3, TRUE);
                              state = 40;
                            break;
                            default:
                              printf ("ERROR: packed_string_integer_greater_than returned unknown value.\n");
                              state = 999;
                            break;
                          }
                        }
                        else
                        {
                          printf ("ERROR: malloc failed.\n");
                          state = 999;
                        }
                      }
                      else
                      {
                        if ((packed_string_float1 != NULL) && (packed_string_float2 != NULL))
                        {
                          bool_value3 = (unsigned char *) malloc(sizeof(unsigned char));
                          bool_value3_is_a_temporary_variable = FALSE; // mark as FALSE because copy of pointer is on the stack. IF we release memory immediately, stack will point to empty free'd value.
                          if (bool_value3 != NULL)
                          {
                            *bool_value3 = packed_string_float_greater_than (packed_string_float1, packed_string_float2);
                            switch (*bool_value3)
                            {
                              case 0:
                              case 1:
                                temp_expression_stack = push_operand_runtime_expression_stack (temp_expression_stack, _bool, bool_value3, TRUE);
                                state = 40;
                              break;
                              default:
                                printf ("ERROR: packed_string_integer_greater_than returned unknown value.\n");
                                state = 999;
                              break;
                            }
                          }
                          else
                          {
                            printf ("ERROR: malloc failed.\n");
                            state = 999;
                          }
                        }
                        else
                        {
                          printf ("ERROR: datatype mismatch.\n");
                          state = 999;
                        }
                      }
                    break;
                    case _less_than_or_equal:
// *********************************************
// * Perform the LESS_THAN_OR_EQUAL operation. *
// *********************************************
                      if ((packed_string_integer1 != NULL) && (packed_string_integer2 != NULL))
                      {
                        bool_value3 = (unsigned char *) malloc(sizeof(unsigned char));
                        bool_value3_is_a_temporary_variable = FALSE; // mark as FALSE because copy of pointer is on the stack. IF we release memory immediately, stack will point to empty free'd value.
                        if (bool_value3 != NULL)
                        {
                          *bool_value3 = packed_string_integer_less_than_or_equal (packed_string_integer1, packed_string_integer2);
                          switch (*bool_value3)
                          {
                            case 0:
                            case 1:
                              temp_expression_stack = push_operand_runtime_expression_stack (temp_expression_stack, _bool, bool_value3, TRUE);
                              state = 40;
                            break;
                            default:
                              printf ("ERROR: packed_string_integer_less_than_or_equal returned unknown value.\n");
                              state = 999;
                            break;
                          }
                        }
                        else
                        {
                          printf ("ERROR: malloc failed.\n");
                          state = 999;
                        }
                      }
                      else
                      {
                        if ((packed_string_float1 != NULL) && (packed_string_float2 != NULL))
                        {
                          bool_value3 = (unsigned char *) malloc(sizeof(unsigned char));
                          bool_value3_is_a_temporary_variable = FALSE; // mark as FALSE because copy of pointer is on the stack. IF we release memory immediately, stack will point to empty free'd value.
                          if (bool_value3 != NULL)
                          {
                            *bool_value3 = packed_string_float_less_than_or_equal (packed_string_float1, packed_string_float2);
                            switch (*bool_value3)
                            {
                              case 0:
                              case 1:
                                temp_expression_stack = push_operand_runtime_expression_stack (temp_expression_stack, _bool, bool_value3, TRUE);
                                state = 40;
                              break;
                              default:
                                printf ("ERROR: packed_string_integer_less_than_or_equal returned unknown value.\n");
                                state = 999;
                              break;
                            }
                          }
                          else
                          {
                            printf ("ERROR: malloc failed.\n");
                            state = 999;
                          }
                        }
                        else
                        {
                          printf ("ERROR: datatype mismatch.\n");
                          state = 999;
                        }
                      }
                    break;
                    case _less_than:
// ************************************
// * Perform the LESS THAN operation. *
// ************************************
                      if ((packed_string_integer1 != NULL) && (packed_string_integer2 != NULL))
                      {
                        bool_value3 = (unsigned char *) malloc(sizeof(unsigned char));
                        bool_value3_is_a_temporary_variable = FALSE; // mark as FALSE because copy of pointer is on the stack. IF we release memory immediately, stack will point to empty free'd value.
                        if (bool_value3 != NULL)
                        {
                          *bool_value3 = packed_string_integer_less_than (packed_string_integer1, packed_string_integer2);
                          switch (*bool_value3)
                          {
                            case 0:
                            case 1:
                              temp_expression_stack = push_operand_runtime_expression_stack (temp_expression_stack, _bool, bool_value3, TRUE);
                              state = 40;
                            break;
                            default:
                              printf ("ERROR: packed_string_integer_less_than returned unknown value.\n");
                              state = 999;
                            break;
                          }
                        }
                        else
                        {
                          printf ("ERROR: malloc failed.\n");
                          state = 999;
                        }
                      }
                      else
                      {
                        if ((packed_string_float1 != NULL) && (packed_string_float2 != NULL))
                        {
                          bool_value3 = (unsigned char *) malloc(sizeof(unsigned char));
                          bool_value3_is_a_temporary_variable = FALSE; // mark as FALSE because copy of pointer is on the stack. IF we release memory immediately, stack will point to empty free'd value.
                          if (bool_value3 != NULL)
                          {
                            *bool_value3 = packed_string_float_less_than (packed_string_float1, packed_string_float2);
                            switch (*bool_value3)
                            {
                              case 0:
                              case 1:
                                temp_expression_stack = push_operand_runtime_expression_stack (temp_expression_stack, _bool, bool_value3, TRUE);
                                state = 40;
                              break;
                              default:
                                printf ("ERROR: packed_string_integer_less_than returned unknown value.\n");
                                state = 999;
                              break;
                            }
                          }
                          else
                          {
                            printf ("ERROR: malloc failed.\n");
                            state = 999;
                          }
                        }
                        else
                        {
                          printf ("ERROR: datatype mismatch.\n");
                          state = 999;
                        }
                      }
                    break;
                    case _equal:
// ********************************
// * Perform the EQUAL operation. *
// ********************************
                      if ((packed_string_integer1 != NULL) && (packed_string_integer2 != NULL))
                      {
                        bool_value3 = (unsigned char *) malloc(sizeof(unsigned char));
                        bool_value3_is_a_temporary_variable = FALSE; // mark as FALSE because copy of pointer is on the stack. IF we release memory immediately, stack will point to empty free'd value.
                        if (bool_value3 != NULL)
                        {
                          *bool_value3 = packed_string_integer_equal (packed_string_integer1, packed_string_integer2);
                          switch (*bool_value3)
                          {
                            case 0:
                            case 1:
                              temp_expression_stack = push_operand_runtime_expression_stack (temp_expression_stack, _bool, bool_value3, TRUE);
                              state = 40;
                            break;
                            default:
                              printf ("ERROR: packed_string_integer_equal returned unknown value.\n");
                              state = 999;
                            break;
                          }
                        }
                        else
                        {
                          printf ("ERROR: malloc failed.\n");
                          state = 999;
                        }
                      }
                      else
                      {
                        if ((packed_string_float1 != NULL) && (packed_string_float2 != NULL))
                        {
                          bool_value3 = (unsigned char *) malloc(sizeof(unsigned char));
                          bool_value3_is_a_temporary_variable = FALSE; // mark as FALSE because copy of pointer is on the stack. IF we release memory immediately, stack will point to empty free'd value.
                          if (bool_value3 != NULL)
                          {
                            *bool_value3 = packed_string_float_equal (packed_string_float1, packed_string_float2);
                            switch (*bool_value3)
                            {
                              case 0:
                              case 1:
                                temp_expression_stack = push_operand_runtime_expression_stack (temp_expression_stack, _bool, bool_value3, TRUE);
                                state = 40;
                              break;
                              default:
                                printf ("ERROR: packed_string_integer_equal returned unknown value.\n");
                                state = 999;
                              break;
                            }
                          }
                          else
                          {
                            printf ("ERROR: malloc failed.\n");
                            state = 999;
                          }
                        }
                        else
                        {
                          printf ("ERROR: datatype mismatch.\n");
                          state = 999;
                        }
                      }
                    break;
                    case _not_equal:
// ************************************
// * Perform the NOT EQUAL operation. *
// ************************************
                      if ((packed_string_integer1 != NULL) && (packed_string_integer2 != NULL))
                      {
                        bool_value3 = (unsigned char *) malloc(sizeof(unsigned char));
                        bool_value3_is_a_temporary_variable = FALSE; // mark as FALSE because copy of pointer is on the stack. IF we release memory immediately, stack will point to empty free'd value.
                        if (bool_value3 != NULL)
                        {
                          *bool_value3 = packed_string_integer_not_equal (packed_string_integer1, packed_string_integer2);
                          switch (*bool_value3)
                          {
                            case 0:
                            case 1:
                              temp_expression_stack = push_operand_runtime_expression_stack (temp_expression_stack, _bool, bool_value3, TRUE);
                              state = 40;
                            break;
                            default:
                              printf ("ERROR: packed_string_integer_not_equal returned unknown value.\n");
                              state = 999;
                            break;
                          }
                        }
                        else
                        {
                          printf ("ERROR: malloc failed.\n");
                          state = 999;
                        }
                      }
                      else
                      {
                        if ((packed_string_float1 != NULL) && (packed_string_float2 != NULL))
                        {
                          bool_value3 = (unsigned char *) malloc(sizeof(unsigned char));
                          bool_value3_is_a_temporary_variable = FALSE; // mark as FALSE because copy of pointer is on the stack. IF we release memory immediately, stack will point to empty free'd value.
                          if (bool_value3 != NULL)
                          {
                            *bool_value3 = packed_string_float_not_equal (packed_string_float1, packed_string_float2);
                            switch (*bool_value3)
                            {
                              case 0:
                              case 1:
                                temp_expression_stack = push_operand_runtime_expression_stack (temp_expression_stack, _bool, bool_value3, TRUE);
                                state = 40;
                              break;
                              default:
                                printf ("ERROR: packed_string_integer_not_equal returned unknown value.\n");
                                state = 999;
                              break;
                            }
                          }
                          else
                          {
                            printf ("ERROR: malloc failed.\n");
                            state = 999;
                          }
                        }
                        else
                        {
                          printf ("ERROR: datatype mismatch.\n");
                          state = 999;
                        }
                      }
                    break;
                    default:
                      printf ("ERROR: unknown operator.\n");
                      state = 999;
                    break;
                  }
                }
              break;
// ************************************************************************************
// * For operators AND, OR, XOR: both operands must be converted to BOOLEAN datatype. *
// ************************************************************************************
              case _and:
              case _or:
              case _xor:
                expression_stack = pop_runtime_expression_stack (expression_stack);
                if (temp_expression_stack != NULL)
                {
                  if (temp_expression_stack->operator == _none)
                  {
                    if (temp_expression_stack->operand != NULL)
                    {
                      switch (temp_expression_stack->operand_type)
                      {
                        case _int:
                          packed_string_integer2 = (psint *) temp_expression_stack->operand;
                          packed_string_integer2_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                          temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                        break;
                        case _float:
                          packed_string_float2 = (psflt *) temp_expression_stack->operand;
                          packed_string_float2_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                          temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                        break;
                        case _bool:
                          bool_value2 = (unsigned char *) temp_expression_stack->operand;
                          bool_value2_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                          temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                        break;
                        case _constant_int:
                          string_length = strlen ((unsigned char *) temp_expression_stack->operand) + 1;
                          if (string_length > 1)
                          {
                            constant_integer2 = (unsigned char *) malloc(sizeof(unsigned char) * string_length);
                            if (constant_integer2 != NULL)
                            {
                              strncpy (constant_integer2, (unsigned char *) temp_expression_stack->operand, string_length);
                              constant_integer2_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                              temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                            }
                            else
                            {
                              state = 999;
                            }
                          }
                        break;
                        case _constant_float:
                          string_length = strlen ((unsigned char *) temp_expression_stack->operand) + 1;
                          if (string_length > 1)
                          {
                            constant_float2 = (unsigned char *) malloc(sizeof(unsigned char) * string_length);
                            if (constant_float2 != NULL)
                            {
                              strncpy (constant_float2, (unsigned char *) temp_expression_stack->operand, string_length);
                              constant_float2_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                              temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                            }
                            else
                            {
                              state = 999;
                            }
                          }
                        break;
                        case _constant_bool:
                          constant_boolean2 = (unsigned char *) temp_expression_stack->operand;
                          constant_boolean2_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                          temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                        break;
                        default:
                          printf ("ERROR: Unknown operand\n");
                          state = 999;
                        break;
                      }
                    }
                  }
                }
                if (temp_expression_stack != NULL)
                {
                  if (temp_expression_stack->operator == _none)
                  {
                    if (temp_expression_stack->operand != NULL)
                    {
                      switch (temp_expression_stack->operand_type)
                      {
                        case _int:
                          packed_string_integer1 = (psint *) temp_expression_stack->operand;
                          packed_string_integer1_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                          temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                        break;
                        case _float:
                          packed_string_float1 = (psflt *) temp_expression_stack->operand;
                          packed_string_float1_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                          temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                        break;
                        case _bool:
                          bool_value1 = (unsigned char *) temp_expression_stack->operand;
                          bool_value1_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                          temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                        break;
                        case _constant_int:
                          string_length = strlen ((unsigned char *) temp_expression_stack->operand) + 1;
                          if (string_length > 1)
                          {
                            constant_integer1 = (unsigned char *) malloc(sizeof(unsigned char) * string_length);
                            if (constant_integer1 != NULL)
                            {
                              strncpy (constant_integer1, (unsigned char *) temp_expression_stack->operand, string_length);
                              constant_integer1_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                              temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                            }
                            else
                            {
                              state = 999;
                            }
                          }
                        break;
                        case _constant_float:
                          string_length = strlen ((unsigned char *) temp_expression_stack->operand) + 1;
                          if (string_length > 1)
                          {
                            constant_float1 = (unsigned char *) malloc(sizeof(unsigned char) * string_length);
                            if (constant_float1 != NULL)
                            {
                              strncpy (constant_float1, (unsigned char *) temp_expression_stack->operand, string_length);
                              constant_float1_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                              temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                            }
                            else
                            {
                              state = 999;
                            }
                          }
                        break;
                        case _constant_bool:
                          constant_boolean1 = (unsigned char *) temp_expression_stack->operand;
                          constant_boolean1_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                          temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                        break;
                        default:
                          printf ("ERROR: Unknown operand\n");
                          state = 999;
                        break;
                      }
                    }
                  }
                }
// ***********************************************************************************************
// * Convert the first operand datatype (if applicable) to Boolean for the Boolean AND operator. *
// ***********************************************************************************************
                if (state < 999)
                {
                  if (constant_boolean1 != NULL)
                  {
                    bool_value1 = convert_boolean_string_to_boolean (constant_boolean1);
                    bool_value1_is_a_temporary_variable = TRUE;
                  }
                  else
                  {
                    if (constant_integer1 != NULL)
                    {
                      packed_string_integer1 = packed_string_integer_set_value (packed_string_integer1, constant_integer1);
                      packed_string_integer1_is_a_temporary_variable = TRUE;
                      bool_value1 = convert_packed_string_integer_to_boolean (packed_string_integer1);
                      bool_value1_is_a_temporary_variable = TRUE;
                    }
                    else
                    {
                      if (constant_float1 != NULL)
                      {
                        packed_string_float1 = packed_string_float_set_value (packed_string_float1, constant_float1);
                        packed_string_float1_is_a_temporary_variable = TRUE;
                        bool_value1 = convert_packed_string_float_to_boolean (packed_string_float1);
                        bool_value1_is_a_temporary_variable = TRUE;
                      }
                      else
                      {
                        if (packed_string_integer1 != NULL)
                        {
                          bool_value1 = convert_packed_string_integer_to_boolean (packed_string_integer1);
                          bool_value1_is_a_temporary_variable = TRUE;
                        }
                        else
                        {
                          if (packed_string_float1 != NULL)
                          {
                            bool_value1 = convert_packed_string_float_to_boolean (packed_string_float1);
                            bool_value1_is_a_temporary_variable = TRUE;
                          }
                        }
                      }
                    }
                  }
                }
// *******************************************************************
// * Convert the second operand datatype (if applicable) to Boolean. *
// *******************************************************************
                if (state < 999)
                {
                  if (constant_boolean2 != NULL)
                  {
                    bool_value2 = convert_boolean_string_to_boolean (constant_boolean2);
                    bool_value2_is_a_temporary_variable = TRUE;
                  }
                  else
                  {
                    if (constant_integer2 != NULL)
                    {
                      packed_string_integer2 = packed_string_integer_set_value (packed_string_integer2, constant_integer2);
                      bool_value2 = convert_packed_string_integer_to_boolean (packed_string_integer2);
                      bool_value2_is_a_temporary_variable = TRUE;
                    }
                    else
                    {
                      if (constant_float2 != NULL)
                      {
                        packed_string_float2 = packed_string_float_set_value (packed_string_float2, constant_float2);
                        packed_string_float2_is_a_temporary_variable = TRUE;
                        bool_value2 = convert_packed_string_float_to_boolean (packed_string_float2);
                        bool_value2_is_a_temporary_variable = TRUE;
                      }
                      else
                      {
                        if (packed_string_integer2 != NULL)
                        {
                          bool_value2 = convert_packed_string_integer_to_boolean (packed_string_integer2);
                          bool_value2_is_a_temporary_variable = TRUE;
                        }
                        else
                        {
                          if (packed_string_float2 != NULL)
                          {
                            bool_value2 = convert_packed_string_float_to_boolean (packed_string_float2);
                            bool_value2_is_a_temporary_variable = TRUE;
                          }
                        }
                      }
                    }
                  }
                }
                if (state < 999)
                {
                  switch (operator)
                  {
                    case _and:
// **********************************
// * Now perform the AND operation. *
// **********************************
                      if ((bool_value1 != NULL) && (bool_value2 != NULL))
                      {
                        bool_value3 = (unsigned char *) malloc(sizeof(unsigned char));
                        if (bool_value3 != NULL)
                        {
                          *bool_value3 = (*bool_value1) && (*bool_value2);
                          temp_expression_stack = push_operand_runtime_expression_stack (temp_expression_stack, _bool, bool_value3, TRUE);
                          bool_value3_is_a_temporary_variable = FALSE; // mark as FALSE because copy of pointer is on the stack. If I release memory immediately, stack will point to empty free'd value.
                          state = 40;
                        }
                      }
                    break;
                    case _or:
// *********************************
// * Now perform the OR operation. *
// *********************************
                      if ((bool_value1 != NULL) && (bool_value2 != NULL))
                      {
                        bool_value3 = (unsigned char *) malloc(sizeof(unsigned char));
                        if (bool_value3 != NULL)
                        {
                          *bool_value3 = (*bool_value1) || (*bool_value2);
                          temp_expression_stack = push_operand_runtime_expression_stack (temp_expression_stack, _bool, bool_value3, TRUE);
                          bool_value3_is_a_temporary_variable = FALSE; // mark as FALSE because copy of pointer is on the stack. If I release memory immediately, stack will point to empty free'd value.
                          state = 40;
                        }
                      }
                    break;
                    case _xor:
// **********************************
// * Now perform the XOR operation. *
// **********************************
                      if ((bool_value1 != NULL) && (bool_value2 != NULL))
                      {
                        bool_value3 = boolean_xor (bool_value1, bool_value2);
                        temp_expression_stack = push_operand_runtime_expression_stack (temp_expression_stack, _bool, bool_value3, TRUE);
                        bool_value3_is_a_temporary_variable = FALSE; // mark as FALSE because copy of pointer is on the stack. If I release memory immediately, stack will point to empty free'd value.
                        state = 40;
                      }
                    break;
                    default:
                      printf ("ERROR: unknown operator.\n");
                      state = 999;
                    break;
                  }
                } 
              break;
// ********************************************************************************
// * Operator PLUS: Both operands must be converted to INTEGER OR FLOAT datatype. *
// ********************************************************************************
              case _plus:
              case _minus:
              case _times:
              case _divide:
                expression_stack = pop_runtime_expression_stack (expression_stack);
                if (temp_expression_stack != NULL)
                {
                  if (temp_expression_stack->operator == _none)
                  {
                    if (temp_expression_stack->operand != NULL)
                    {
                      switch (temp_expression_stack->operand_type)
                      {
                        case _int:
                          packed_string_integer2 = (psint *) temp_expression_stack->operand;
                          packed_string_integer2_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                          temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                        break;
                        case _float:
                          packed_string_float2 = (psflt *) temp_expression_stack->operand;
                          packed_string_float2_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                          temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                        break;
                        case _bool:
                          bool_value2 = (unsigned char *) temp_expression_stack->operand;
                          bool_value2_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                          temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                        break;
                        case _constant_int:
                          string_length = strlen ((unsigned char *) temp_expression_stack->operand) + 1;
                          if (string_length > 1)
                          {
                            constant_integer2 = (unsigned char *) malloc(sizeof(unsigned char) * string_length);
                            if (constant_integer2 != NULL)
                            {
                              strncpy (constant_integer2, (unsigned char *) temp_expression_stack->operand, string_length);
                              constant_integer2_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                              temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                            }
                            else
                            {
                              state = 999;
                            }
                          }
                        break;
                        case _constant_float:
                          string_length = strlen ((unsigned char *) temp_expression_stack->operand) + 1;
                          if (string_length > 1)
                          {
                            constant_float2 = (unsigned char *) malloc(sizeof(unsigned char) * string_length);
                            if (constant_float2 != NULL)
                            {
                              strncpy (constant_float2, (unsigned char *) temp_expression_stack->operand, string_length);
                              constant_float2_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                              temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                            }
                            else
                            {
                              state = 999;
                            }
                          }
                        break;
                        case _constant_bool:
                          constant_boolean2 = (unsigned char *) temp_expression_stack->operand;
                          constant_boolean2_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                          temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                        break;
                        default:
                          printf ("ERROR: Unknown operand\n");
                          state = 999;
                        break;
                      }
                    }
                  }
                }
                if (temp_expression_stack != NULL)
                {
                  if (temp_expression_stack->operator == _none)
                  {
                    if (temp_expression_stack->operand != NULL)
                    {
                      switch (temp_expression_stack->operand_type)
                      {
                        case _int:
                          packed_string_integer1 = (psint *) temp_expression_stack->operand;
                          packed_string_integer1_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                          temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                        break;
                        case _float:
                          packed_string_float1 = (psflt *) temp_expression_stack->operand;
                          packed_string_float1_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                          temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                        break;
                        case _bool:
                          bool_value1 = (unsigned char *) temp_expression_stack->operand;
                          bool_value1_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                          temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                        break;
                        case _constant_int:
                          string_length = strlen ((unsigned char *) temp_expression_stack->operand) + 1;
                          if (string_length > 1)
                          {
                            constant_integer1 = (unsigned char *) malloc(sizeof(unsigned char) * string_length);
                            if (constant_integer1 != NULL)
                            {
                              strncpy (constant_integer1, (unsigned char *) temp_expression_stack->operand, string_length);
                              constant_integer1_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                              temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                            }
                            else
                            {
                              state = 999;
                            }
                          }
                        break;
                        case _constant_float:
                          string_length = strlen ((unsigned char *) temp_expression_stack->operand) + 1;
                          if (string_length > 1)
                          {
                            constant_float1 = (unsigned char *) malloc(sizeof(unsigned char) * string_length);
                            if (constant_float1 != NULL)
                            {
                              strncpy (constant_float1, (unsigned char *) temp_expression_stack->operand, string_length);
                              constant_float1_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                              temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                            }
                            else
                            {
                              state = 999;
                            }
                          }
                        break;
                        case _constant_bool:
                          constant_boolean1 = (unsigned char *) temp_expression_stack->operand;
                          constant_boolean1_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                          temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                        break;
                        default:
                          printf ("ERROR: Unknown operand\n");
                          state = 999;
                        break;
                      }
                    }
                  }
                }
// **********************************************************************************************************************
// * Convert both operand1 and operand2 to integer datatype or float datatype for: ADD, SUBTRACT, MULTIPLY, and DIVIDE. *
// **********************************************************************************************************************
                if (state < 999)
                {
                  if (constant_integer1 != NULL)
                  {
                    if (constant_integer2 != NULL)
                    {
                      packed_string_integer1 = packed_string_integer_set_value (packed_string_integer1, constant_integer1);
                      packed_string_integer1_is_a_temporary_variable = TRUE;
                      packed_string_integer2 = packed_string_integer_set_value (packed_string_integer2, constant_integer2);
                      packed_string_integer2_is_a_temporary_variable = TRUE;
                    }
                    else
                    {
                      if (constant_float2 != NULL)
                      {
                        packed_string_float1 = packed_string_float_set_value (packed_string_float1, constant_integer1);
                        packed_string_float1_is_a_temporary_variable = TRUE;
                        packed_string_float2 = packed_string_float_set_value (packed_string_float2, constant_float2);
                        packed_string_float2_is_a_temporary_variable = TRUE;
                      }
                      else
                      {
                        if (constant_boolean2 != NULL)
                        {
                          packed_string_integer1 = packed_string_integer_set_value (packed_string_integer1, constant_integer1);
                          packed_string_integer1_is_a_temporary_variable = TRUE;
                          packed_string_integer2 = convert_boolean_string_to_packed_string_integer (constant_boolean2);
                          packed_string_integer2_is_a_temporary_variable = TRUE;
                        }
                        else
                        {
                          if (packed_string_integer2 != NULL)
                          {
                            packed_string_integer1 = packed_string_integer_set_value (packed_string_integer1, constant_integer1);
                            packed_string_integer1_is_a_temporary_variable = TRUE;
                          }
                          else
                          {
                            if (packed_string_float2 != NULL)
                            {
                              packed_string_float1 = packed_string_float_set_value (packed_string_float1, constant_integer1);
                              packed_string_float1_is_a_temporary_variable = TRUE;
                            }
                            else
                            {
                              if (bool_value2 != NULL)
                              {
                                packed_string_integer1 = packed_string_integer_set_value (packed_string_integer1, constant_integer1);
                                packed_string_integer1_is_a_temporary_variable = TRUE;
                                packed_string_integer2 = convert_boolean_to_packed_string_integer (bool_value2);
                                packed_string_integer2_is_a_temporary_variable = TRUE;
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                  else
                  {
                    if (constant_float1 != NULL)
                    {
                      packed_string_float1 = packed_string_float_set_value (packed_string_float1, constant_float1);
                      packed_string_float1_is_a_temporary_variable = TRUE;
                      if (constant_integer2 != NULL)
                      {
                        packed_string_float2 = packed_string_float_set_value (packed_string_float2, constant_integer2);
                        packed_string_float2_is_a_temporary_variable = TRUE;
                      }
                      else
                      {
                        if (constant_float2 != NULL)
                        {
                          packed_string_float2 = packed_string_float_set_value (packed_string_float2, constant_float2);
                          packed_string_float2_is_a_temporary_variable = TRUE;
                        }
                        else
                        {
                          if (constant_boolean2 != NULL)
                          {
                            packed_string_float2 = convert_boolean_string_to_packed_string_float (constant_boolean2);
                            packed_string_float2_is_a_temporary_variable = TRUE;
                          }
                          else
                          {
                            if (packed_string_integer2 != NULL)
                            {
                              packed_string_float2 = convert_packed_string_integer_to_packed_string_float (packed_string_float2, packed_string_integer2); 
                              packed_string_float2_is_a_temporary_variable = TRUE;
                            }
                            else
                            {
                              if (bool_value2 != NULL)
                              {
                                packed_string_float2 = convert_boolean_to_packed_string_float (bool_value2);
                                packed_string_float2_is_a_temporary_variable = TRUE;
                              }
                            }
                          }
                        }
                      }
                    }
                    else
                    {
                      if (packed_string_integer1 != NULL)
                      {
                        if (constant_integer2 != NULL)
                        {
                          packed_string_integer2 = packed_string_integer_set_value (packed_string_integer2, constant_integer2);
                          packed_string_integer2_is_a_temporary_variable = TRUE;
                        }
                        else
                        {
                          if (constant_float2 != NULL)
                          {
                            packed_string_float1 = convert_packed_string_integer_to_packed_string_float (packed_string_float1, packed_string_integer1); 
                            packed_string_float1_is_a_temporary_variable = TRUE;
                            packed_string_float2 = packed_string_float_set_value (packed_string_float2, constant_float2);
                            packed_string_float2_is_a_temporary_variable = TRUE;
                          }
                          else
                          {
                            if (constant_boolean2 != NULL)
                            {
                              packed_string_integer2 = convert_boolean_string_to_packed_string_integer (constant_boolean2);
                              packed_string_integer2_is_a_temporary_variable = TRUE;
                            }
                            else
                            {
                              if (packed_string_float2 != NULL)
                              {
                                packed_string_float1 = convert_packed_string_integer_to_packed_string_float (packed_string_float1, packed_string_integer1); 
                                packed_string_float1_is_a_temporary_variable = TRUE;
                              }
                              else
                              {
                                if (bool_value2 != NULL)
                                {
                                  packed_string_float1 = convert_packed_string_integer_to_packed_string_float (packed_string_float1, packed_string_integer1); 
                                  packed_string_float1_is_a_temporary_variable = TRUE;
                                  packed_string_float2 = convert_boolean_to_packed_string_float (bool_value2);
                                  packed_string_float2_is_a_temporary_variable = TRUE;
                                }
                              }
                            }
                          }
                        }
                      }
                      else
                      {
                        if (packed_string_float1 != NULL)
                        {
                          if (constant_integer2 != NULL)
                          {
                            packed_string_float2 = packed_string_float_set_value (packed_string_float2, constant_integer2);
                            packed_string_float2_is_a_temporary_variable = TRUE;
                          }
                          else
                          {
                            if (constant_float2 != NULL)
                            {
                              packed_string_float2 = packed_string_float_set_value (packed_string_float2, constant_float2);
                              packed_string_float2_is_a_temporary_variable = TRUE;
                            }
                            else
                            {
                              if (constant_boolean2 != NULL)
                              {
                                packed_string_float2 = convert_boolean_string_to_packed_string_float (constant_boolean2);
                                packed_string_float2_is_a_temporary_variable = TRUE;
                              }
                              else
                              {
                                if (packed_string_integer2 != NULL)
                                {
                                  packed_string_float2 = convert_packed_string_integer_to_packed_string_float (packed_string_float2, packed_string_integer2); 
                                  packed_string_float2_is_a_temporary_variable = TRUE;
                                }
                                else
                                {
                                  if (bool_value2 != NULL)
                                  {
                                    packed_string_float2 = convert_boolean_to_packed_string_float (bool_value2);
                                    packed_string_float2_is_a_temporary_variable = TRUE;
                                  }
                                }
                              }
                            }
                          }
                        }
                        else
                        {
                          if (constant_boolean1 != NULL)
                          {
                            if (constant_boolean2 != NULL)
                            {
                              packed_string_integer1 = convert_boolean_string_to_packed_string_integer (constant_boolean1);
                              packed_string_integer1_is_a_temporary_variable = TRUE;
                              packed_string_integer2 = convert_boolean_string_to_packed_string_integer (constant_boolean2);
                              packed_string_integer2_is_a_temporary_variable = TRUE;
                            }
                            else
                            {
                              if (constant_integer2 != NULL)
                              {
                                packed_string_integer1 = convert_boolean_string_to_packed_string_integer (constant_boolean1);
                                packed_string_integer1_is_a_temporary_variable = TRUE;
                                packed_string_integer2 = packed_string_integer_set_value (packed_string_integer2, constant_integer2);
                                packed_string_integer2_is_a_temporary_variable = TRUE;
                              }
                              else
                              {
                                if (constant_float2 != NULL)
                                {
                                  packed_string_float1 = convert_boolean_string_to_packed_string_float (constant_boolean1);
                                  packed_string_float1_is_a_temporary_variable = TRUE;
                                  packed_string_float2 = packed_string_float_set_value (packed_string_float2, constant_float2);
                                  packed_string_float2_is_a_temporary_variable = TRUE;
                                }
                                else
                                {
                                  if (packed_string_integer2 != NULL)
                                  {
                                    packed_string_integer1 = convert_boolean_string_to_packed_string_integer (constant_boolean1);
                                    packed_string_integer1_is_a_temporary_variable = TRUE;
                                  }
                                  else
                                  {
                                    if (packed_string_float2 != NULL)
                                    {
                                      packed_string_float1 = convert_boolean_string_to_packed_string_float (constant_boolean1);
                                      packed_string_float1_is_a_temporary_variable = TRUE;
                                    }
                                  }
                                }
                              }
                            }
                          }
                          else
                          {
                            if (bool_value1 != NULL)
                            {
                              if (constant_boolean2 != NULL)
                              {
                                packed_string_integer1 = convert_boolean_to_packed_string_integer (bool_value1);
                                packed_string_integer1_is_a_temporary_variable = TRUE;
                                packed_string_integer2 = convert_boolean_string_to_packed_string_integer (constant_boolean2);
                                packed_string_integer2_is_a_temporary_variable = TRUE;
                              }
                              else
                              {
                                if (constant_integer2 != NULL)
                                {
                                  packed_string_integer1 = convert_boolean_to_packed_string_integer (bool_value1);
                                  packed_string_integer1_is_a_temporary_variable = TRUE;
                                  packed_string_integer2 = packed_string_integer_set_value (packed_string_integer2, constant_integer2);
                                  packed_string_integer2_is_a_temporary_variable = TRUE;
                                }
                                else
                                {
                                  if (constant_float2 != NULL)
                                  {
                                    packed_string_float1 = convert_boolean_to_packed_string_float (bool_value1);
                                    packed_string_float1_is_a_temporary_variable = TRUE;
                                    packed_string_float2 = packed_string_float_set_value (packed_string_float2, constant_float2);
                                    packed_string_float2_is_a_temporary_variable = TRUE;
                                  }
                                  else
                                  {
                                    if (packed_string_integer2 != NULL)
                                    {
                                      packed_string_integer1 = convert_boolean_to_packed_string_integer (bool_value1);
                                      packed_string_integer1_is_a_temporary_variable = TRUE;
                                    }
                                    else
                                    {
                                      if (packed_string_float2 != NULL)
                                      {
                                        packed_string_float1 = convert_boolean_to_packed_string_float (bool_value1);
                                        packed_string_float1_is_a_temporary_variable = TRUE;
                                      }
                                      else
                                      {
                                        if (bool_value2 != NULL)
                                        {
                                          packed_string_integer1 = convert_boolean_to_packed_string_integer (bool_value1);
                                          packed_string_integer1_is_a_temporary_variable = TRUE;
                                          packed_string_integer2 = convert_boolean_to_packed_string_integer (bool_value2);
                                          packed_string_integer2_is_a_temporary_variable = TRUE;
                                        }
                                      }
                                    }
                                  }
                                }
                              } 
                            }
                          }
                        }
                      }
                    }
                  }
                  switch (operator)
                  {
                    case _plus:
// ******************************
// * Perform the ADD operation. *
// ******************************
                      if ((packed_string_integer1 != NULL) && (packed_string_integer2 != NULL))
                      {
                        packed_string_integer3 = packed_string_integer_add (packed_string_integer3, packed_string_integer1, packed_string_integer2);
                        packed_string_integer3_is_a_temporary_variable = FALSE; // don't want to release memory immediately since it is on the stack. On the stack it is marked as temporary to release at later iteration.
                        if (packed_string_integer3 != NULL)
                        {
                          temp_expression_stack = push_operand_runtime_expression_stack (temp_expression_stack, _int, packed_string_integer3, TRUE);
                          state = 40;
                        }
                        else
                        {
                          printf ("ERROR: packed_string_integer_add returned NULL.\n");
                          state = 999;
                        }
                      }
                      else
                      {
                        if ((packed_string_float1 != NULL) && (packed_string_float2 != NULL))
                        {
                          packed_string_float3 = packed_string_float_add (packed_string_float3, packed_string_float1, packed_string_float2);
                          packed_string_float3_is_a_temporary_variable = FALSE; // don't want to release memory immediately since it is on the stack. On the stack it is marked as temporary to release at later iteration.
                          if (packed_string_float3 != NULL)
                          {
                            temp_expression_stack = push_operand_runtime_expression_stack (temp_expression_stack, _float, packed_string_float3, TRUE);
                            state = 40;
                          }
                          else
                          {
                            printf ("ERROR: packed_string_integer_add returned NULL.\n");
                            state = 999;
                          }
                        }
                        else
                        {
                          printf ("ERROR: operand1 and operand2 are not of like-datatypes. Cannot compute the sum.\n");
                          state = 999;
                        }
                      }
                    break;
                    case _minus:
// ***********************************
// * Perform the SUBTRACT operation. *
// ***********************************
                      if ((packed_string_integer1 != NULL) && (packed_string_integer2 != NULL))
                      {
                        packed_string_integer3 = packed_string_integer_subtract (packed_string_integer3, packed_string_integer1, packed_string_integer2);
                        packed_string_integer3_is_a_temporary_variable = FALSE; // don't want to release memory immediately since it is on the stack. On the stack it is marked as temporary to release at later iteration.
                        if (packed_string_integer3 != NULL)
                        {
                          temp_expression_stack = push_operand_runtime_expression_stack (temp_expression_stack, _int, packed_string_integer3, TRUE);
                          state = 40;
                        }
                        else
                        {
                          printf ("ERROR: packed_string_integer_subtract returned NULL.\n");
                          state = 999;
                        }
                      }
                      else
                      {
                        if ((packed_string_float1 != NULL) && (packed_string_float2 != NULL))
                        {
                          packed_string_float3 = packed_string_float_subtract (packed_string_float3, packed_string_float1, packed_string_float2);
                          packed_string_float3_is_a_temporary_variable = FALSE; // don't want to release memory immediately since it is on the stack. On the stack it is marked as temporary to release at later iteration.
                          if (packed_string_float3 != NULL)
                          {
                            temp_expression_stack = push_operand_runtime_expression_stack (temp_expression_stack, _float, packed_string_float3, TRUE);
                            state = 40;
                          }
                          else
                          {
                            printf ("ERROR: packed_string_integer_subtract returned NULL.\n");
                            state = 999;
                          }
                        }
                        else
                        {
                          printf ("ERROR: operand1 and operand2 are not of like-datatypes. Cannot compute the difference.\n");
                          state = 999;
                        }
                      }
                    break;
                    case _times:
// ***********************************
// * Perform the MULTIPLY operation. *
// ***********************************
                      if ((packed_string_integer1 != NULL) && (packed_string_integer2 != NULL))
                      {
                        packed_string_integer3 = packed_string_integer_multiply (packed_string_integer3, packed_string_integer1, packed_string_integer2);
                        packed_string_integer3_is_a_temporary_variable = FALSE; // don't want to release memory immediately since it is on the stack. On the stack it is marked as temporary to release at later iteration.
                        if (packed_string_integer3 != NULL)
                        {
                          temp_expression_stack = push_operand_runtime_expression_stack (temp_expression_stack, _int, packed_string_integer3, TRUE);
                          state = 40;
                        }
                        else
                        {
                          printf ("ERROR: packed_string_integer_multiply returned NULL.\n");
                          state = 999;
                        }
                      }
                      else
                      {
                        if ((packed_string_float1 != NULL) && (packed_string_float2 != NULL))
                        {
                          packed_string_float3 = packed_string_float_multiply (packed_string_float3, packed_string_float1, packed_string_float2);
                          packed_string_float3_is_a_temporary_variable = FALSE; // don't want to release memory immediately since it is on the stack. On the stack it is marked as temporary to release at later iteration.
                          if (packed_string_float3 != NULL)
                          {
                            temp_expression_stack = push_operand_runtime_expression_stack (temp_expression_stack, _float, packed_string_float3, TRUE);
                            state = 40;
                          }
                          else
                          {
                            printf ("ERROR: packed_string_integer_multiply returned NULL.\n");
                            state = 999;
                          }
                        }
                        else
                        {
                          printf ("ERROR: operand1 and operand2 are not of like-datatypes. Cannot compute the product.\n");
                          state = 999;
                        }
                      }
                    break;
                    case _divide:
// *********************************
// * Perform the DIVIDE operation. *
// *********************************
                      if ((packed_string_integer1 != NULL) && (packed_string_integer2 != NULL))
                      {
                        packed_string_integer3 = packed_string_integer_divide (packed_string_integer3, packed_string_integer1, packed_string_integer2);
                        packed_string_integer3_is_a_temporary_variable = FALSE; // don't want to release memory immediately since it is on the stack. On the stack it is marked as temporary to release at later iteration.
                        if (packed_string_integer3 != NULL)
                        {
                          temp_expression_stack = push_operand_runtime_expression_stack (temp_expression_stack, _int, packed_string_integer3, TRUE);
                          state = 40;
                        }
                        else
                        {
                          printf ("ERROR: packed_string_integer_divide returned NULL.\n");
                          state = 999;
                        }
                      }
                      else
                      {
                        if ((packed_string_float1 != NULL) && (packed_string_float2 != NULL))
                        {
                          packed_string_float3 = packed_string_float_divide (packed_string_float3, packed_string_float1, packed_string_float2, 100); // scale hardcoded to 100 digits after decimal. Need to change this to appropriate user-defined value later.
                          packed_string_float3_is_a_temporary_variable = FALSE; // don't want to release memory immediately since it is on the stack. On the stack it is marked as temporary to release at later iteration.
                          if (packed_string_float3 != NULL)
                          {
                            temp_expression_stack = push_operand_runtime_expression_stack (temp_expression_stack, _float, packed_string_float3, TRUE);
                            state = 40;
                          }
                          else
                          {
                            printf ("ERROR: packed_string_float_divide returned NULL.\n");
                            state = 999;
                          }
                        }
                        else
                        {
                          printf ("ERROR: operand1 and operand2 are not of like-datatypes. Cannot compute the quotient.\n");
                          state = 999;
                        }
                      }
                    break;
                    default:
                      printf ("ERROR: Unknown operator\n");
                      state = 999;
                    break;
                  }
                }
              break;
// ******************************************************************************************************************************
// * Operator MODULO: both datatypes must be converted to integer since the modulo function only operates on integer datatypes. *
// ******************************************************************************************************************************
              case _modulo:
                expression_stack = pop_runtime_expression_stack (expression_stack);
                if (temp_expression_stack != NULL)
                {
                  if (temp_expression_stack->operator == _none)
                  {
                    if (temp_expression_stack->operand != NULL)
                    {
                      switch (temp_expression_stack->operand_type)
                      {
                        case _int:
                          packed_string_integer2 = (psint *) temp_expression_stack->operand;
                          packed_string_integer2_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                          temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                        break;
                        case _float:
                          packed_string_float2 = (psflt *) temp_expression_stack->operand;
                          packed_string_float2_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                          temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                        break;
                        case _bool:
                          bool_value2 = (unsigned char *) temp_expression_stack->operand;
                          bool_value2_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                          temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                        break;
                        case _constant_int:
                          string_length = strlen ((unsigned char *) temp_expression_stack->operand) + 1;
                          if (string_length > 1)
                          {
                            constant_integer2 = (unsigned char *) malloc(sizeof(unsigned char) * string_length);
                            if (constant_integer2 != NULL)
                            {
                              strncpy (constant_integer2, (unsigned char *) temp_expression_stack->operand, string_length);
                              constant_integer2_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                              temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                            }
                            else
                            {
                              state = 999;
                            }
                          }
                        break;
                        case _constant_float:
                          string_length = strlen ((unsigned char *) temp_expression_stack->operand) + 1;
                          if (string_length > 1)
                          {
                            constant_float2 = (unsigned char *) malloc(sizeof(unsigned char) * string_length);
                            if (constant_float2 != NULL)
                            {
                              strncpy (constant_float2, (unsigned char *) temp_expression_stack->operand, string_length);
                              constant_float2_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                              temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                            }
                            else
                            {
                              state = 999;
                            }
                          }
                        break;
                        case _constant_bool:
                          constant_boolean2 = (unsigned char *) temp_expression_stack->operand;
                          constant_boolean2_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                          temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                        break;
                        default:
                          printf ("ERROR: Unknown operand\n");
                          state = 999;
                        break;
                      }
                    }
                  }
                }
                if (temp_expression_stack != NULL)
                {
                  if (temp_expression_stack->operator == _none)
                  {
                    if (temp_expression_stack->operand != NULL)
                    {
                      switch (temp_expression_stack->operand_type)
                      {
                        case _int:
                          packed_string_integer1 = (psint *) temp_expression_stack->operand;
                          packed_string_integer1_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                          temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                        break;
                        case _float:
                          packed_string_float1 = (psflt *) temp_expression_stack->operand;
                          packed_string_float1_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                          temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                        break;
                        case _bool:
                          bool_value1 = (unsigned char *) temp_expression_stack->operand;
                          bool_value1_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                          temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                        break;
                        case _constant_int:
                          string_length = strlen ((unsigned char *) temp_expression_stack->operand) + 1;
                          if (string_length > 1)
                          {
                            constant_integer1 = (unsigned char *) malloc(sizeof(unsigned char) * string_length);
                            if (constant_integer1 != NULL)
                            {
                              strncpy (constant_integer1, (unsigned char *) temp_expression_stack->operand, string_length);
                              constant_integer1_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                              temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                            }
                            else
                            {
                              state = 999;
                            }
                          }
                        break;
                        case _constant_float:
                          string_length = strlen ((unsigned char *) temp_expression_stack->operand) + 1;
                          if (string_length > 1)
                          {
                            constant_float1 = (unsigned char *) malloc(sizeof(unsigned char) * string_length);
                            if (constant_float1 != NULL)
                            {
                              strncpy (constant_float1, (unsigned char *) temp_expression_stack->operand, string_length);
                              constant_float1_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                              temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                            }
                            else
                            {
                              state = 999;
                            }
                          }
                        break;
                        case _constant_bool:
                          constant_boolean1 = (unsigned char *) temp_expression_stack->operand;
                          constant_boolean1_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                          temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                        break;
                        default:
                          printf ("ERROR: Unknown operand\n");
                          state = 999;
                        break;
                      }
                    }
                  }
                }
// **********************************************************************************************************
// * Convert both operand1 and operand2 to integer datatype since MODULO only works with INTEGER datatypes. *
// **********************************************************************************************************
                if (state < 999)
                {
                  if (constant_integer1 != NULL)
                  {
                    packed_string_integer1 = packed_string_integer_set_value (packed_string_integer1, constant_integer1);
                    packed_string_integer1_is_a_temporary_variable = TRUE;
                    if (constant_integer2 != NULL)
                    {
                      packed_string_integer2 = packed_string_integer_set_value (packed_string_integer2, constant_integer2);
                      packed_string_integer2_is_a_temporary_variable = TRUE;
                    }
                    else
                    {
                      if (constant_float2 != NULL)
                      {
                        packed_string_float2 = packed_string_float_set_value (packed_string_float2, constant_float2);
                        packed_string_float2_is_a_temporary_variable = TRUE;
                        packed_string_integer2 = packed_string_float_truncate_to_packed_string_integer (packed_string_integer2, packed_string_float2);
                        packed_string_integer2_is_a_temporary_variable = TRUE;
                      }
                      else
                      {
                        if (constant_boolean2 != NULL)
                        {
                          packed_string_integer2 = convert_boolean_string_to_packed_string_integer (constant_boolean2);
                          packed_string_integer2_is_a_temporary_variable = TRUE;
                        }
                        else
                        {
                          if (packed_string_float2 != NULL)
                          {
                            packed_string_integer2 = packed_string_float_truncate_to_packed_string_integer (packed_string_integer2, packed_string_float2);
                            packed_string_integer2_is_a_temporary_variable = TRUE;
                          }
                          else
                          {
                            if (bool_value2 != NULL)
                            {
                              packed_string_integer2 = convert_boolean_to_packed_string_integer (bool_value2);
                              packed_string_integer2_is_a_temporary_variable = TRUE;
                            }
                          }
                        }
                      }
                    }
                  }
                  else
                  {
                    if (constant_float1 != NULL)
                    {
                      packed_string_float1 = packed_string_float_set_value (packed_string_float1, constant_float1);
                      packed_string_float1_is_a_temporary_variable = TRUE;
                      packed_string_integer1 = packed_string_float_truncate_to_packed_string_integer (packed_string_integer1, packed_string_float1);
                      packed_string_integer1_is_a_temporary_variable = TRUE;
                      if (constant_float2 != NULL)
                      {
                        packed_string_float2 = packed_string_float_set_value (packed_string_float2, constant_float2);
                        packed_string_float2_is_a_temporary_variable = TRUE;
                        packed_string_integer2 = packed_string_float_truncate_to_packed_string_integer (packed_string_integer2, packed_string_float2);
                        packed_string_integer2_is_a_temporary_variable = TRUE;
                      }
                      else
                      {
                        if (constant_integer2 != NULL)
                        {
                          packed_string_integer2 = packed_string_integer_set_value (packed_string_integer2, constant_integer2);
                          packed_string_integer2_is_a_temporary_variable = TRUE;
                        }
                        else
                        {
                          if (constant_boolean2 != NULL)
                          {
                            packed_string_integer2 = convert_boolean_string_to_packed_string_integer (constant_boolean2);
                            packed_string_integer2_is_a_temporary_variable = TRUE;
                          }
                          else
                          {
                            if (packed_string_float2 != NULL)
                            {
                              packed_string_integer2 = packed_string_float_truncate_to_packed_string_integer (packed_string_integer2, packed_string_float2);
                              packed_string_integer2_is_a_temporary_variable = TRUE;
                            }
                            else
                            {
                              if (bool_value2 != NULL)
                              {
                                packed_string_integer2 = convert_boolean_to_packed_string_integer (bool_value2);
                                packed_string_integer2_is_a_temporary_variable = TRUE;
                              }
                            }
                          }
                        }
                      }
                    }
                    else
                    {
                      if (packed_string_integer1 != NULL)
                      {
                        if (constant_integer2 != NULL)
                        {
                          packed_string_integer2 = packed_string_integer_set_value (packed_string_integer2, constant_integer2);
                          packed_string_integer2_is_a_temporary_variable = TRUE;
                        }
                        else
                        {
                          if (constant_float2 != NULL)
                          {
                            packed_string_float2 = packed_string_float_set_value (packed_string_float2, constant_float2);
                            packed_string_float2_is_a_temporary_variable = TRUE;
                            packed_string_integer2 = packed_string_float_truncate_to_packed_string_integer (packed_string_integer2, packed_string_float2);
                            packed_string_integer2_is_a_temporary_variable = TRUE;
                          }
                          else
                          {
                            if (constant_boolean2 != NULL)
                            {
                              packed_string_integer2 = convert_boolean_string_to_packed_string_integer (constant_boolean2);
                              packed_string_integer2_is_a_temporary_variable = TRUE;
                            }
                            else
                            {
                              if (packed_string_float2 != NULL)
                              {
                                packed_string_integer2 = packed_string_float_truncate_to_packed_string_integer (packed_string_integer2, packed_string_float2);
                                packed_string_integer2_is_a_temporary_variable = TRUE;
                              }
                              else
                              {
                                if (bool_value2 != NULL)
                                {
                                  packed_string_integer2 = convert_boolean_to_packed_string_integer (bool_value2);
                                  packed_string_integer2_is_a_temporary_variable = TRUE;
                                }
                              }
                            }
                          }
                        }
                      }
                      else
                      {
                        if (packed_string_float1 != NULL)
                        {
                          packed_string_integer1 = packed_string_float_truncate_to_packed_string_integer (packed_string_integer1, packed_string_float1);
                          packed_string_integer1_is_a_temporary_variable = TRUE;
                          if (constant_integer2 != NULL)
                          {
                            packed_string_integer2 = packed_string_integer_set_value (packed_string_integer2, constant_integer2);
                            packed_string_integer2_is_a_temporary_variable = TRUE;
                          }
                          else
                          { 
                            if (constant_float2 != NULL)
                            {
                              packed_string_float2 = packed_string_float_set_value (packed_string_float2, constant_float2);
                              packed_string_float2_is_a_temporary_variable = TRUE;
                              packed_string_integer2 = packed_string_float_truncate_to_packed_string_integer (packed_string_integer2, packed_string_float2);
                              packed_string_integer2_is_a_temporary_variable = TRUE;
                            }
                            else
                            {
                              if (constant_boolean2 != NULL)
                              {
                                packed_string_integer2 = convert_boolean_string_to_packed_string_integer (constant_boolean2);
                                packed_string_integer2_is_a_temporary_variable = TRUE;
                              }
                              else
                              {
                                if (packed_string_float2 != NULL)
                                {
                                  packed_string_integer2 = packed_string_float_truncate_to_packed_string_integer (packed_string_integer2, packed_string_float2);
                                  packed_string_integer2_is_a_temporary_variable = TRUE;
                                }
                                else
                                {
                                  if (bool_value2 != NULL)
                                  {
                                    packed_string_integer2 = convert_boolean_to_packed_string_integer (bool_value2);
                                    packed_string_integer2_is_a_temporary_variable = TRUE;
                                  }
                                }
                              }
                            }
                          }
                        }
                        else
                        {
                          if (constant_boolean1 != NULL)
                          {
                            packed_string_integer1 = convert_boolean_string_to_packed_string_integer (constant_boolean1);
                            packed_string_integer1_is_a_temporary_variable = TRUE;
                            if (constant_boolean2 != NULL)
                            {
                              packed_string_integer2 = convert_boolean_string_to_packed_string_integer (constant_boolean2);
                              packed_string_integer2_is_a_temporary_variable = TRUE;
                            }
                            else
                            {
                              if (constant_float2 != NULL)
                              {
                                packed_string_float2 = packed_string_float_set_value (packed_string_float2, constant_float2);
                                packed_string_float2_is_a_temporary_variable = TRUE;
                                packed_string_integer2 = packed_string_float_truncate_to_packed_string_integer (packed_string_integer2, packed_string_float2);
                                packed_string_integer2_is_a_temporary_variable = TRUE;
                              }
                              else
                              {
                                if (constant_integer2 != NULL)
                                {
                                  packed_string_integer2 = packed_string_integer_set_value (packed_string_integer2, constant_integer2);
                                  packed_string_integer2_is_a_temporary_variable = TRUE;
                                }
                                else
                                {
                                  if (packed_string_float2 != NULL)
                                  {
                                    packed_string_integer2 = packed_string_float_truncate_to_packed_string_integer (packed_string_integer2, packed_string_float2);
                                    packed_string_integer2_is_a_temporary_variable = TRUE;
                                  }
                                }
                              }
                            }
                          }
                          else
                          {
                            if (bool_value1 != NULL)
                            {
                              packed_string_integer1 = convert_boolean_to_packed_string_integer (bool_value1);
                              packed_string_integer1_is_a_temporary_variable = TRUE;
                              if (constant_boolean2 != NULL)
                              {
                                packed_string_integer2 = convert_boolean_string_to_packed_string_integer (constant_boolean2);
                                packed_string_integer2_is_a_temporary_variable = TRUE;
                              }
                              else
                              {
                                if (constant_integer2 != NULL)
                                {
                                  packed_string_integer2 = packed_string_integer_set_value (packed_string_integer2, constant_integer2);
                                  packed_string_integer2_is_a_temporary_variable = TRUE;
                                }
                                else
                                {
                                  if (constant_float2 != NULL)
                                  {
                                    packed_string_float2 = packed_string_float_set_value (packed_string_float2, constant_float2);
                                    packed_string_float2_is_a_temporary_variable = TRUE;
                                    packed_string_integer2 = packed_string_float_truncate_to_packed_string_integer (packed_string_integer2, packed_string_float2);
                                    packed_string_integer2_is_a_temporary_variable = TRUE;
                                  }
                                  else
                                  {
                                    if (bool_value2 != NULL)
                                    {
                                      packed_string_integer2 = convert_boolean_to_packed_string_integer (bool_value2);
                                      packed_string_integer2_is_a_temporary_variable = TRUE;
                                    }
                                    else
                                    {
                                      if (packed_string_float2 != NULL)
                                      {
                                        packed_string_integer2 = packed_string_float_truncate_to_packed_string_integer (packed_string_integer2, packed_string_float2);
                                        packed_string_integer2_is_a_temporary_variable = TRUE;
                                      }
                                    }
                                  }
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
// *********************************
// * Perform the MODULO operation. *
// *********************************
                  if ((packed_string_integer1 != NULL) && (packed_string_integer2 != NULL))
                  {
                    packed_string_integer3 = packed_string_integer_modulo (packed_string_integer3, packed_string_integer1, packed_string_integer2);
                    packed_string_integer3_is_a_temporary_variable = FALSE; // don't want to release memory immediately since it is on the stack. On the stack it is marked as temporary to release at later iteration.
                    if (packed_string_integer3 != NULL)
                    {
                      temp_expression_stack = push_operand_runtime_expression_stack (temp_expression_stack, _int, packed_string_integer3, TRUE);
                      state = 40;
                    }
                    else
                    {
                      printf ("ERROR: packed_string_integer_modulo returned NULL.\n");
                      state = 999;
                    }
                  }
                  else
                  {
                    printf ("ERROR: operand1 and operand2 are not INTEGER datatypes. Cannot compute modulo.\n");
                    state = 999;
                  }
                }
              break;
// *******************************************************************************
// * Operator NOT: Only one operator is necessary since NOT is a unary operator. *
// *******************************************************************************
              case _not:
                expression_stack = pop_runtime_expression_stack (expression_stack);
                if (temp_expression_stack != NULL)
                {
                  if (temp_expression_stack->operator == _none)
                  {
                    if (temp_expression_stack->operand != NULL)
                    {
                      switch (temp_expression_stack->operand_type)
                      {
                        case _int:
                          packed_string_integer1 = (psint *) temp_expression_stack->operand;
                          packed_string_integer1_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                          temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                        break;
                        case _float:
                          packed_string_float1 = (psflt *) temp_expression_stack->operand;
                          packed_string_float1_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                          temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                        break;
                        case _bool:
                          bool_value1 = (unsigned char *) temp_expression_stack->operand;
                          bool_value1_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                          temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                        break;
                        case _constant_int:
                          string_length = strlen ((unsigned char *) temp_expression_stack->operand) + 1;
                          if (string_length > 1)
                          {
                            constant_integer1 = (unsigned char *) malloc(sizeof(unsigned char) * string_length);
                            if (constant_integer1 != NULL)
                            {
                              strncpy (constant_integer1, (unsigned char *) temp_expression_stack->operand, string_length);
                              constant_integer1_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                              temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                            }
                            else
                            {
                              state = 999;
                            }
                          }
                        break;
                        case _constant_float:
                          string_length = strlen ((unsigned char *) temp_expression_stack->operand) + 1;
                          if (string_length > 1)
                          {
                            constant_float1 = (unsigned char *) malloc(sizeof(unsigned char) * string_length);
                            if (constant_float1 != NULL)
                            {
                              strncpy (constant_float1, (unsigned char *) temp_expression_stack->operand, string_length);
                              constant_float1_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                              temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                            }
                            else
                            {
                              state = 999;
                            }
                          }
                        break;
                        case _constant_bool:
                          constant_boolean1 = (unsigned char *) temp_expression_stack->operand;
                          constant_boolean1_is_a_temporary_variable = temp_expression_stack->ok_to_free_memory_for_operand;
                          temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
                        break;
                        default:
                          printf ("ERROR: Unknown operand\n");
                          state = 999;
                        break;
                      }
                    }
                  }
                }
// *****************************************************************************************
// * Convert the operand datatype (if applicable) to Boolean for the Boolean NOT operator. *
// *****************************************************************************************
                if (state < 999)
                {
                  if (constant_boolean1 != NULL)
                  {
                    bool_value1 = convert_boolean_string_to_boolean (constant_boolean1);
                    bool_value1_is_a_temporary_variable = TRUE;
                  }
                  else
                  {
                    if (constant_integer1 != NULL)
                    {
                      packed_string_integer1 = packed_string_integer_set_value (packed_string_integer1, constant_integer1);
                      packed_string_integer1_is_a_temporary_variable = TRUE;
                      bool_value1 = convert_packed_string_integer_to_boolean (packed_string_integer1);
                      bool_value1_is_a_temporary_variable = TRUE;
                    }
                    else
                    {
                      if (constant_float1 != NULL)
                      {
                        packed_string_float1 = packed_string_float_set_value (packed_string_float1, constant_float1);
                        packed_string_float1_is_a_temporary_variable = TRUE;
                        bool_value1 = convert_packed_string_float_to_boolean (packed_string_float1);
                        bool_value1_is_a_temporary_variable = TRUE;
                      }
                      else
                      {
                        if (packed_string_integer1 != NULL)
                        {
                          bool_value1 = convert_packed_string_integer_to_boolean (packed_string_integer1);
                          bool_value1_is_a_temporary_variable = TRUE;
                        }
                        else
                        {
                          if (packed_string_float1 != NULL)
                          {
                            bool_value1 = convert_packed_string_float_to_boolean (packed_string_float1);
                            bool_value1_is_a_temporary_variable = TRUE;
                          }
                        }
                      }
                    }
                  }
                }
// **********************************
// * Now perform the NOT operation. *
// **********************************
                if (state < 999)
                {
                  if (bool_value1 != NULL)
                  {
                    bool_value3 = (unsigned char *) malloc(sizeof(unsigned char));
                    if (bool_value3 != NULL)
                    {
                      switch (*bool_value1)
                      {
                        case TRUE:
                          *bool_value3 = FALSE;
                        break;
                        case FALSE:
                          *bool_value3 = TRUE;
                        break;
                        default:
                          *bool_value3 = FALSE;
                        break;
                      }
                      temp_expression_stack = push_operand_runtime_expression_stack (temp_expression_stack, _bool, bool_value3, TRUE);
                      bool_value3_is_a_temporary_variable = FALSE; // mark as FALSE because copy of pointer is on the stack. IF we release memory immediately, stack will point to empty free'd value.
                      state = 40;
                    }
                  }
                }
              break;
// ********************************
// * Unexpected UNKNOWN operator. *
// ********************************
              default:
                printf ("ERROR: Unknown operator encountered.\n");
                state = 999;
              break;
            }
          }
          else
          {
            printf ("ERROR: expected operator but none found.\n");
            state = 999;
          }
        }
        else
        {
          printf ("ERROR: expression stack missing expected operator.\n");
          state = 999;
        }
      break;
// ***************************************************************************************************
// * State 40: Remove any temporary variables created during the evaluation process (if applicable). *
// ***************************************************************************************************
      case 40:
        if (constant_integer1 != NULL)
        {
          if (constant_integer1_is_a_temporary_variable)
          {
            free (constant_integer1);
            constant_integer1 = NULL;
          }
        }
        if (constant_integer2 != NULL)
        {
          if (constant_integer2_is_a_temporary_variable)
          {
            free (constant_integer2); 
            constant_integer2 = NULL;
          }
        }
        if (constant_float1 != NULL)
        {
          free (constant_float1); // it is safe to always release the string pointers since they have been copied and converted to string integers or another datatype.
          constant_float1 = NULL;
        }
        if (constant_float2 != NULL)
        {
          free (constant_float2); // it is safe to always release the string pointers since they have been copied and converted to string integers or another datatype.
          constant_float2 = NULL;
        }
        if (packed_string_integer1 != NULL)
        {
          if (packed_string_integer1_is_a_temporary_variable)
          {
            packed_string_integer1 = packed_string_integer_release_memory (packed_string_integer1);
          }
        }
        if (packed_string_integer2 != NULL)
        {
          if (packed_string_integer2_is_a_temporary_variable)
          {
            packed_string_integer2 = packed_string_integer_release_memory (packed_string_integer2);
          }  
        }
        if (packed_string_integer3 != NULL)
        {
          if (packed_string_integer3_is_a_temporary_variable)
          {
            packed_string_integer3 = packed_string_integer_release_memory (packed_string_integer3);
          }  
        }
        if (packed_string_float1 != NULL)
        {
          if (packed_string_float1_is_a_temporary_variable)
          {
            packed_string_float1 = packed_string_float_release_memory (packed_string_float1);
          }
        }
        if (packed_string_float2 != NULL)
        {
          if (packed_string_float2_is_a_temporary_variable)
          {
            packed_string_float2 = packed_string_float_release_memory (packed_string_float2);
          }  
        }
        if (packed_string_float3 != NULL)
        {
          if (packed_string_float3_is_a_temporary_variable)
          {
            packed_string_float3 = packed_string_float_release_memory (packed_string_float3);
          }  
        }
        if (bool_value1 != NULL)
        {
          if (bool_value1_is_a_temporary_variable)
          {
            free (bool_value1);
            bool_value1 = NULL;
          }
        }
        if (bool_value2 != NULL)
        {
          if (bool_value2_is_a_temporary_variable)
          {
            free (bool_value2);
            bool_value1 = NULL;
          }
        }
        if (bool_value3 != NULL)
        {
          if (bool_value3_is_a_temporary_variable)
          {
            free (bool_value3);
            bool_value1 = NULL;
          }
	}
        state = 0;
      break;
      default:
        printf ("ERROR: Unknown state reached. Exiting now.\n");
        state = 999;
      break;
    }
  }
  //printf ("Leaving main while loop, state = %d\n", state);
  if (state == 999)
  {
    while (temp_expression_stack != NULL)
    {
      temp_expression_stack = pop_runtime_expression_stack (temp_expression_stack);
    }
    while (expression_stack != NULL)
    {
      expression_stack = pop_runtime_expression_stack (expression_stack);
    }
  }
  else
  {
    if (state == 1000)
    {
      expression_stack_list = temp_expression_stack;
    }
  }
  return expression_stack_list;
}
