2019-01-08 22:19:29 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
void printValue(object input);
|
|
|
|
|
2019-02-19 09:49:55 +01:00
|
|
|
int Print(object input)
|
2019-01-08 22:19:29 +01:00
|
|
|
{
|
2019-11-30 20:18:21 +01:00
|
|
|
switch (TYPE(input))
|
2019-01-14 03:16:25 +01:00
|
|
|
{
|
2019-11-30 20:18:21 +01:00
|
|
|
case errorObject:
|
2019-02-18 23:20:44 +01:00
|
|
|
fprintf(stderr, "\nГРЕШКА: %s\n\n", ERR(input));
|
2019-11-30 20:18:21 +01:00
|
|
|
break;
|
|
|
|
case EOFObject:
|
2019-02-09 19:55:51 +01:00
|
|
|
return 0;
|
2019-11-30 20:18:21 +01:00
|
|
|
break;
|
|
|
|
case unspecifiedObject:
|
|
|
|
break;
|
|
|
|
default:
|
2019-01-20 23:48:12 +01:00
|
|
|
printf("\n");
|
2019-01-14 03:16:25 +01:00
|
|
|
printValue(input);
|
|
|
|
printf("\n\n");
|
2019-11-30 20:18:21 +01:00
|
|
|
break;
|
2019-01-14 03:16:25 +01:00
|
|
|
}
|
2019-11-03 14:02:03 +01:00
|
|
|
|
2019-02-09 19:55:51 +01:00
|
|
|
return 1;
|
2019-01-08 22:19:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void printValue(object input)
|
|
|
|
{
|
2019-02-03 18:57:49 +01:00
|
|
|
switch (TYPE(input))
|
2019-01-08 22:19:29 +01:00
|
|
|
{
|
2019-02-03 18:57:49 +01:00
|
|
|
case nilObject:
|
2019-01-14 03:16:25 +01:00
|
|
|
printf("()");
|
2019-02-03 18:57:49 +01:00
|
|
|
break;
|
|
|
|
case consObject:
|
2019-01-08 22:19:29 +01:00
|
|
|
printf("(");
|
2019-01-17 09:38:09 +01:00
|
|
|
object *currentCell = &input;
|
|
|
|
while (TYPE(*currentCell) == consObject)
|
|
|
|
{
|
|
|
|
printValue(CAR(*currentCell));
|
|
|
|
if (TYPE(CDR(*currentCell)) == consObject)
|
|
|
|
{
|
|
|
|
printf(" ");
|
|
|
|
}
|
|
|
|
currentCell = &CDR(*currentCell);
|
|
|
|
}
|
|
|
|
if (TYPE(*currentCell) != nilObject)
|
|
|
|
{
|
|
|
|
printf(" . ");
|
|
|
|
printValue(*currentCell);
|
|
|
|
}
|
2019-01-08 22:19:29 +01:00
|
|
|
printf(")");
|
2019-02-03 18:57:49 +01:00
|
|
|
break;
|
|
|
|
case numberObject:
|
|
|
|
if (NUM_TYPE(input) == fractionNum)
|
|
|
|
{
|
|
|
|
printf("%lld", NUM_NUMER(input));
|
|
|
|
if (NUM_DENOM(input) != 1)
|
|
|
|
{
|
|
|
|
printf("/%lld", NUM_DENOM(input));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("%LF", NUM_REAL(input));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case symbolObject:
|
|
|
|
printf("%s", SYM(input));
|
|
|
|
break;
|
|
|
|
case procedureObject:
|
|
|
|
printf("<процедура:%s>", PROC_TYPE(input) == builtinProc ?
|
|
|
|
"уграђена" : "сложена");
|
|
|
|
break;
|
|
|
|
case boolObject:
|
|
|
|
printf("#%s", BOOL(input) ? "и" : "л");
|
|
|
|
break;
|
|
|
|
case stringObject:
|
|
|
|
printf("\"%s\"", STR(input));
|
|
|
|
break;
|
|
|
|
case charObject:
|
|
|
|
printf("#\\");
|
|
|
|
switch (CHR(input))
|
|
|
|
{
|
|
|
|
case L' ':
|
|
|
|
printf("размак");
|
|
|
|
break;
|
|
|
|
case L'\n':
|
|
|
|
printf("новиред");
|
|
|
|
break;
|
|
|
|
case L'\t':
|
|
|
|
printf("табулар");
|
|
|
|
break;
|
2019-02-28 23:43:33 +01:00
|
|
|
case L'\0':
|
|
|
|
printf("нул");
|
2019-08-23 19:11:14 +02:00
|
|
|
break;
|
2019-02-03 18:57:49 +01:00
|
|
|
default:
|
|
|
|
printf("%lc", CHR(input));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2019-01-08 22:19:29 +01:00
|
|
|
}
|
|
|
|
}
|
2019-11-03 14:02:03 +01:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void PrintEntry(entry *e)
|
|
|
|
{
|
|
|
|
if (e == NULL)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
PrintEntry(e->left);
|
|
|
|
printf("%s: ", e->name);
|
|
|
|
Print(e->value);
|
|
|
|
PrintEntry(e->right);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrintEnv(env environment)
|
|
|
|
{
|
|
|
|
printf("%p", (void *) environment);
|
|
|
|
env enclosings = environment->enclosing;
|
|
|
|
while (enclosings != NULL)
|
|
|
|
{
|
|
|
|
printf(" <-- %p", (void *) enclosings);
|
|
|
|
enclosings = enclosings->enclosing;
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
PrintEntry(environment->table);
|
|
|
|
}
|
|
|
|
#endif
|