cirilisp/print.c

66 lines
1.3 KiB
C
Raw Normal View History

#include <stdio.h>
#include "util.h"
char *errors[] =
{
"Конс објекат мора бити правилна листа да би могао бити евалуиран",
"Неправилан тип аргумента прослеђен функцији",
"Непознати симбол",
"Објекат није примењив",
"Дељење нулом",
"Функцији није прослеђен правилан број аргумената"
};
void printValue(object input);
void print(object input)
{
if (input.type == errorObject)
{
fprintf(stderr, "\nГРЕШКА: %s\n\n", errors[ERR(input)]);
}
else
{
printf("\n; Value: ");
printValue(input);
printf("\n\n");
}
}
void printValue(object input)
{
if (input.type == nilObject)
{
printf("()");
}
else if (input.type == numberObject)
{
printf("%lld", NUM(input));
}
else if (input.type == symbolObject)
{
printf("%s", SYM(input));
}
else if (input.type == consObject)
{
printf("(");
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);
}
printf(")");
}
}