2019-01-08 22:19:29 +01:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
#include "util.h"
|
|
|
|
|
|
2019-01-16 23:24:23 +01:00
|
|
|
|
char *errors[] =
|
|
|
|
|
{
|
|
|
|
|
"Конс објекат мора бити правилна листа да би могао бити евалуиран",
|
|
|
|
|
"Неправилан тип аргумента прослеђен функцији",
|
|
|
|
|
"Непознати симбол",
|
|
|
|
|
"Објекат није примењив",
|
|
|
|
|
"Дељење нулом",
|
2019-01-20 14:12:47 +01:00
|
|
|
|
"Функцији није прослеђен правилан број аргумената",
|
2019-02-03 18:57:49 +01:00
|
|
|
|
"Пређена је максимална дубина рекурзије",
|
|
|
|
|
"Невалидан карактер",
|
|
|
|
|
"Невалидна тараба-секвенца",
|
|
|
|
|
"Неочекивани крај фајла",
|
|
|
|
|
"Неочекивана заграда",
|
2019-01-16 23:24:23 +01:00
|
|
|
|
};
|
|
|
|
|
|
2019-01-08 22:19:29 +01:00
|
|
|
|
void printValue(object input);
|
|
|
|
|
|
|
|
|
|
void print(object input)
|
|
|
|
|
{
|
2019-01-27 16:31:32 +01:00
|
|
|
|
if (TYPE(input) == errorObject)
|
2019-01-14 03:16:25 +01:00
|
|
|
|
{
|
2019-01-16 23:24:23 +01:00
|
|
|
|
fprintf(stderr, "\nГРЕШКА: %s\n\n", errors[ERR(input)]);
|
2019-01-14 03:16:25 +01:00
|
|
|
|
}
|
2019-02-03 18:57:49 +01:00
|
|
|
|
else if (TYPE(input) != unspecifiedObject)
|
2019-01-14 03:16:25 +01:00
|
|
|
|
{
|
2019-01-20 23:48:12 +01:00
|
|
|
|
printf("\n");
|
2019-01-14 03:16:25 +01:00
|
|
|
|
printValue(input);
|
|
|
|
|
printf("\n\n");
|
|
|
|
|
}
|
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;
|
|
|
|
|
default:
|
|
|
|
|
printf("%lc", CHR(input));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2019-01-08 22:19:29 +01:00
|
|
|
|
}
|
|
|
|
|
}
|