#include <stdio.h>
#include <stdlib.h>

typedef int ErrorCode;
#define FAILURE 1
#define SUCCESS 0

/* TODO In which standard header bool is defined??? */
typedef int bool; 
#define TRUE 1
#define FALSE 0

typedef char BinaryOperator;

/* Convert a string to an operator */
ErrorCode string_to_operator(char * in_string, 
                             BinaryOperator * out_operator);

typedef double Operand;

/* Convert a string to an operand */
ErrorCode string_to_operand(char * in_string, 
                            Operand * out_operand);

/* Evaluate a simple binary expression */
ErrorCode unitary_evaluate(BinaryOperator in_operator, 
			                     Operand in_left_operand, 
			                     Operand in_right_operand, 
			                     Operand * out_result);

/* An element may be an operator or and operand */
typedef enum {
	OperatorType,
	OperandType
} ElementType;

typedef union {
	BinaryOperator operator;
	Operand operand;
} ElementData;

typedef struct {
	ElementType type;
	ElementData data;
} Element;

bool is_operand(Element in_element);
bool is_operator(Element in_element);

/* Convert a string to an element */
ErrorCode string_to_element(char * in_string, 
                            Element * out_element);

/* An array of elements form an expression */
typedef struct {
	size_t element_count;
	Element * elements;
} Expression;

/* Convert command-line arguments to an expression */
ErrorCode cl_arguments_to_expression(size_t in_arg_count, 
                                     char ** in_args, 
                                     Expression * out_expression);

/* Evaluate an expression, set the result in the output parameter */
ErrorCode evaluate(Expression in_expression, 
                   Operand * out_value);

/* Show usage help */
void usage();
