Имплементиран quote навод оператер

This commit is contained in:
kappa 2019-01-19 20:30:52 +01:00
parent 508e5fc9e1
commit cee90aee74
4 changed files with 43 additions and 22 deletions

48
eval.c
View file

@ -14,17 +14,16 @@ object eval(object input)
if (TYPE(input) == nilObject || TYPE(input) == numberObject ||
TYPE(input) == errorObject)
{
result = input;
result = copyObject(input);
}
else if (TYPE(input) == symbolObject)
{
if (symbolExists(SYM(input)))
{
result = input;
result = copyObject(input);
}
else
{
deleteObject(input);
TYPE(result) = errorObject;
ERR(result) = unrecognizedSymbolError;
}
@ -33,34 +32,39 @@ object eval(object input)
{
if (!properList(input))
{
deleteObject(input);
TYPE(result) = errorObject;
ERR(result) = improperListError;
}
object *currentCell = &input;
int noErrors = 1;
while (TYPE(*currentCell) != nilObject)
else
{
CAR(*currentCell) = eval(CAR(*currentCell));
if (TYPE(CAR(*currentCell)) == errorObject)
object *currentCell = &input;
int noErrors = 1;
while (TYPE(*currentCell) != nilObject)
{
noErrors = 0;
TYPE(result) = errorObject;
ERR(result) = ERR(CAR(*currentCell));
break;
}
currentCell = &CDR(*currentCell);
}
if (strcmp(SYM(CAR(input)), "навод") != 0)
{
CAR(*currentCell) =
eval(CAR(*currentCell));
}
if (noErrors)
{
result = apply(CAR(input), CDR(input));
if (TYPE(CAR(*currentCell)) == errorObject)
{
noErrors = 0;
TYPE(result) = errorObject;
ERR(result) = ERR(CAR(*currentCell));
break;
}
currentCell = &CDR(*currentCell);
}
if (noErrors)
{
result = apply(CAR(input), CDR(input));
}
}
deleteObject(input);
}
deleteObject(input);
return result;
}

1
init.c
View file

@ -20,4 +20,5 @@ void init()
addSymbolInternal("-", &subtract);
addSymbolInternal("*", &multiply);
addSymbolInternal("/", &divide);
addSymbolInternal("навод", &quote);
}

View file

@ -135,3 +135,18 @@ object divide(object parameters)
return result;
}
object quote(object parameters)
{
object result;
if (listLength(parameters) != 1)
{
TYPE(result) = errorObject;
ERR(result) = argumentNumberError;
}
else
{
result = copyObject(CAR(parameters));
}
return result;
}

View file

@ -4,3 +4,4 @@ object add(object parameters);
object subtract(object parameters);
object multiply(object parameters);
object divide(object parameters);
object quote(object parameters);