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-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
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
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-01-27 16:31:32 +01:00
|
|
|
|
if (TYPE(input) == nilObject)
|
2019-01-08 22:19:29 +01:00
|
|
|
|
{
|
2019-01-14 03:16:25 +01:00
|
|
|
|
printf("()");
|
2019-01-08 22:19:29 +01:00
|
|
|
|
}
|
2019-01-27 16:31:32 +01:00
|
|
|
|
else if (TYPE(input) == numberObject)
|
2019-01-08 22:19:29 +01:00
|
|
|
|
{
|
2019-01-20 23:48:12 +01:00
|
|
|
|
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));
|
|
|
|
|
}
|
2019-01-08 22:19:29 +01:00
|
|
|
|
}
|
2019-01-27 16:31:32 +01:00
|
|
|
|
else if (TYPE(input) == procedureObject)
|
|
|
|
|
{
|
|
|
|
|
printf("<процедура:%s>", PROC_TYPE(input) == builtinProc ?
|
|
|
|
|
"уграђена" : "сложена");
|
2019-01-29 00:07:33 +01:00
|
|
|
|
if (PROC_TYPE(input) == compoundProc)
|
|
|
|
|
{
|
|
|
|
|
printValue(PROC_COMP_ARGS(input));
|
|
|
|
|
printValue(PROC_COMP_BODY(input));
|
|
|
|
|
}
|
2019-01-27 16:31:32 +01:00
|
|
|
|
}
|
|
|
|
|
else if (TYPE(input) == symbolObject)
|
2019-01-08 22:19:29 +01:00
|
|
|
|
{
|
2019-01-14 03:16:25 +01:00
|
|
|
|
printf("%s", SYM(input));
|
2019-01-08 22:19:29 +01:00
|
|
|
|
}
|
2019-01-27 16:31:32 +01:00
|
|
|
|
else if (TYPE(input) == 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(")");
|
|
|
|
|
}
|
|
|
|
|
}
|