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-08 22:19:29 +01:00
|
|
|
|
void printValue(object input);
|
|
|
|
|
|
|
|
|
|
void print(object input)
|
|
|
|
|
{
|
2019-01-14 03:16:25 +01:00
|
|
|
|
if (input.type == errorObject)
|
|
|
|
|
{
|
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
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
printf("\n; Value: ");
|
|
|
|
|
printValue(input);
|
|
|
|
|
printf("\n\n");
|
|
|
|
|
}
|
2019-01-08 22:19:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void printValue(object input)
|
|
|
|
|
{
|
|
|
|
|
if (input.type == nilObject)
|
|
|
|
|
{
|
2019-01-14 03:16:25 +01:00
|
|
|
|
printf("()");
|
2019-01-08 22:19:29 +01:00
|
|
|
|
}
|
|
|
|
|
else if (input.type == numberObject)
|
|
|
|
|
{
|
2019-01-14 03:16:25 +01:00
|
|
|
|
printf("%lld", NUM(input));
|
2019-01-08 22:19:29 +01:00
|
|
|
|
}
|
|
|
|
|
else if (input.type == symbolObject)
|
|
|
|
|
{
|
2019-01-14 03:16:25 +01:00
|
|
|
|
printf("%s", SYM(input));
|
2019-01-08 22:19:29 +01:00
|
|
|
|
}
|
|
|
|
|
else if (input.type == consObject)
|
|
|
|
|
{
|
|
|
|
|
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(")");
|
|
|
|
|
}
|
|
|
|
|
}
|