2019-01-07 01:04:40 +01:00
|
|
|
#pragma once
|
|
|
|
|
2019-02-03 18:57:49 +01:00
|
|
|
#include <wchar.h>
|
|
|
|
|
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-02-03 18:57:49 +01:00
|
|
|
#define STR(x) ((x).value.string)
|
|
|
|
#define CHR(x) ((x).value.character)
|
2019-01-29 23:54:32 +01:00
|
|
|
#define BOOL(x) ((x).value.boolean)
|
2019-01-16 23:24:23 +01:00
|
|
|
#define ERR(x) ((x).value.err)
|
2019-01-14 03:16:25 +01:00
|
|
|
|
2019-02-03 18:57:49 +01:00
|
|
|
#define SIGERR(error) \
|
|
|
|
{\
|
|
|
|
object result;\
|
|
|
|
TYPE(result) = errorObject;\
|
|
|
|
ERR(result) = error;\
|
|
|
|
return result;\
|
|
|
|
}
|
|
|
|
|
2019-01-27 16:31:32 +01:00
|
|
|
#define PROC(x) ((x).value.proc)
|
|
|
|
#define PROC_TYPE(x) ((x).value.proc->type)
|
|
|
|
#define PROC_BUILTIN(x) ((x).value.proc->value.builtin)
|
|
|
|
#define PROC_COMP_ARGS(x) ((x).value.proc->value.compound.args)
|
|
|
|
#define PROC_COMP_BODY(x) ((x).value.proc->value.compound.body)
|
|
|
|
|
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,
|
2019-02-03 18:57:49 +01:00
|
|
|
unspecifiedObject,
|
2019-01-07 01:04:40 +01:00
|
|
|
consObject,
|
|
|
|
numberObject,
|
2019-01-14 03:16:25 +01:00
|
|
|
symbolObject,
|
2019-01-27 16:31:32 +01:00
|
|
|
procedureObject,
|
2019-01-29 23:54:32 +01:00
|
|
|
boolObject,
|
2019-02-03 18:57:49 +01:00
|
|
|
stringObject,
|
|
|
|
charObject,
|
2019-01-14 03:16:25 +01:00
|
|
|
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,
|
2019-01-27 16:31:32 +01:00
|
|
|
maxRecursionDepthError,
|
2019-02-03 18:57:49 +01:00
|
|
|
invalidCharacterError,
|
|
|
|
invalidHashSequenceError,
|
|
|
|
unexpectedEOFError,
|
|
|
|
unmatchedParenError,
|
2019-01-16 23:24:23 +01:00
|
|
|
} error;
|
|
|
|
|
2019-01-20 23:48:12 +01:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
fractionNum,
|
|
|
|
realNum
|
|
|
|
} numType;
|
|
|
|
|
2019-01-27 16:31:32 +01:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
builtinProc,
|
|
|
|
compoundProc
|
|
|
|
} procType;
|
|
|
|
|
|
|
|
typedef struct number number;
|
|
|
|
typedef struct object object;
|
|
|
|
typedef struct cons cons;
|
|
|
|
typedef struct procedure procedure;
|
|
|
|
|
|
|
|
struct number
|
2019-01-20 23:48:12 +01:00
|
|
|
{
|
|
|
|
numType type;
|
|
|
|
union
|
|
|
|
{
|
|
|
|
long double real;
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
long long int numerator;
|
|
|
|
long long int denominator;
|
|
|
|
} fraction;
|
|
|
|
} value;
|
2019-01-27 16:31:32 +01:00
|
|
|
};
|
2019-01-20 23:48:12 +01:00
|
|
|
|
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;
|
2019-02-03 18:57:49 +01:00
|
|
|
char *string;
|
|
|
|
wchar_t character;
|
2019-01-14 03:16:25 +01:00
|
|
|
cons *consCell;
|
2019-01-20 23:48:12 +01:00
|
|
|
number num;
|
2019-01-27 16:31:32 +01:00
|
|
|
procedure *proc;
|
2019-01-29 23:54:32 +01:00
|
|
|
int boolean;
|
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-27 16:31:32 +01:00
|
|
|
struct procedure
|
|
|
|
{
|
|
|
|
procType type;
|
|
|
|
union
|
|
|
|
{
|
|
|
|
object (*builtin)(object);
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
object args;
|
|
|
|
object body;
|
|
|
|
} compound;
|
|
|
|
} value;
|
|
|
|
};
|
|
|
|
|
2019-01-22 00:08:27 +01:00
|
|
|
int isSpecialForm(char *symbol);
|
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);
|
2019-01-21 18:44:56 +01:00
|
|
|
object inexactToExactNum(object a);
|
2019-01-20 23:48:12 +01:00
|
|
|
object plusNum(object a, object b);
|
|
|
|
object minusNum(object a);
|
|
|
|
object timesNum(object a, object b);
|
|
|
|
object inverseNum(object a);
|
2019-01-29 00:07:33 +01:00
|
|
|
|
|
|
|
procedure *createProcedure();
|