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 NUM(x) ((x).value.number)
|
|
|
|
#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-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,
|
|
|
|
argumentNumberError
|
|
|
|
} error;
|
|
|
|
|
|
|
|
typedef struct object object;
|
|
|
|
typedef struct cons cons;
|
|
|
|
|
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;
|
|
|
|
long long int number;
|
|
|
|
cons *consCell;
|
|
|
|
} 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);
|