cirilisp/print.c

67 lines
1.3 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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(")");
}
}