2019-01-07 01:04:40 +01:00
|
|
|
#pragma once
|
|
|
|
|
2019-01-14 03:16:25 +01:00
|
|
|
#define TYPE(x) ((x).type)
|
|
|
|
|
|
|
|
#define CONS(x) ((x).value.consCell)
|
|
|
|
#define CAR(x) (((x).value.consCell)->car)
|
|
|
|
#define CDR(x) (((x).value.consCell)->cdr)
|
|
|
|
#define SYM(x) ((x).value.symbol)
|
2019-01-16 23:24:23 +01:00
|
|
|
#define ERR(x) ((x).value.err)
|
2019-01-14 03:16:25 +01:00
|
|
|
|
2019-01-20 23:48:12 +01:00
|
|
|
#define NUM(x) ((x).value.num)
|
|
|
|
#define NUM_TYPE(x) ((x).value.num.type)
|
|
|
|
#define NUM_NUMER(x) ((x).value.num.value.fraction.numerator)
|
|
|
|
#define NUM_DENOM(x) ((x).value.num.value.fraction.denominator)
|
|
|
|
#define NUM_REAL(x) ((x).value.num.value.real)
|
|
|
|
|
2019-01-07 01:04:40 +01:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
nilObject,
|
|
|
|
consObject,
|
|
|
|
numberObject,
|
2019-01-14 03:16:25 +01:00
|
|
|
symbolObject,
|
|
|
|
errorObject
|
2019-01-07 01:04:40 +01:00
|
|
|
} dataType;
|
|
|
|
|
2019-01-16 23:24:23 +01:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
improperListError,
|
|
|
|
typeError,
|
|
|
|
unrecognizedSymbolError,
|
|
|
|
notApplicableError,
|
|
|
|
divisionByZeroError,
|
2019-01-20 14:12:47 +01:00
|
|
|
argumentNumberError,
|
|
|
|
syntaxError
|
2019-01-16 23:24:23 +01:00
|
|
|
} error;
|
|
|
|
|
|
|
|
typedef struct object object;
|
|
|
|
typedef struct cons cons;
|
|
|
|
|
2019-01-20 23:48:12 +01:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
fractionNum,
|
|
|
|
realNum
|
|
|
|
} numType;
|
|
|
|
|
|
|
|
typedef struct number
|
|
|
|
{
|
|
|
|
numType type;
|
|
|
|
union
|
|
|
|
{
|
|
|
|
long double real;
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
long long int numerator;
|
|
|
|
long long int denominator;
|
|
|
|
} fraction;
|
|
|
|
} value;
|
|
|
|
} number;
|
|
|
|
|
2019-01-14 03:16:25 +01:00
|
|
|
struct object
|
2019-01-07 01:04:40 +01:00
|
|
|
{
|
|
|
|
dataType type;
|
2019-01-14 03:16:25 +01:00
|
|
|
union
|
|
|
|
{
|
2019-01-16 23:24:23 +01:00
|
|
|
error err;
|
2019-01-14 03:16:25 +01:00
|
|
|
char *symbol;
|
|
|
|
cons *consCell;
|
2019-01-20 23:48:12 +01:00
|
|
|
number num;
|
2019-01-14 03:16:25 +01:00
|
|
|
} value;
|
|
|
|
};
|
2019-01-07 01:04:40 +01:00
|
|
|
|
2019-01-14 03:16:25 +01:00
|
|
|
struct cons
|
2019-01-07 01:04:40 +01:00
|
|
|
{
|
|
|
|
object car;
|
|
|
|
object cdr;
|
2019-01-14 03:16:25 +01:00
|
|
|
};
|
2019-01-07 01:04:40 +01:00
|
|
|
|
2019-01-14 03:16:25 +01:00
|
|
|
int properList(object list);
|
|
|
|
int listLength(object list);
|
|
|
|
void deleteObject(object input);
|
|
|
|
object copyObject(object input);
|
2019-01-20 23:48:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
object longlongToNumber(long long int input);
|
|
|
|
object shortenFractionNum(object a);
|
|
|
|
object exactToInexactNum(object a);
|
|
|
|
object plusNum(object a, object b);
|
|
|
|
object minusNum(object a);
|
|
|
|
object timesNum(object a, object b);
|
|
|
|
object inverseNum(object a);
|