cirilisp/print.c

54 lines
1.1 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("(");
printValue(CAR(input));
printf(" . ");
printValue(CDR(input));
printf(")");
}
}