Имплементиран quote навод оператер
This commit is contained in:
parent
508e5fc9e1
commit
cee90aee74
48
eval.c
48
eval.c
|
@ -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
1
init.c
|
@ -20,4 +20,5 @@ void init()
|
|||
addSymbolInternal("-", &subtract);
|
||||
addSymbolInternal("*", &multiply);
|
||||
addSymbolInternal("/", ÷);
|
||||
addSymbolInternal("навод", "e);
|
||||
}
|
||||
|
|
15
internals.c
15
internals.c
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -4,3 +4,4 @@ object add(object parameters);
|
|||
object subtract(object parameters);
|
||||
object multiply(object parameters);
|
||||
object divide(object parameters);
|
||||
object quote(object parameters);
|
||||
|
|
Loading…
Reference in a new issue