|
@@ -8,6 +8,7 @@ import java.util.Queue;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
+import migl.lisp.operator.ConsOperator;
|
|
|
import migl.util.ConsList;
|
|
|
import migl.util.ConsListFactory;
|
|
|
|
|
@@ -21,6 +22,7 @@ public class LispImpl implements Lisp {
|
|
|
private static Map<String, LispOperator> operators = new HashMap<>();
|
|
|
static {
|
|
|
//Définition des opérateurs
|
|
|
+ operators.put("cons", new ConsOperator());
|
|
|
operators.put("quote", (lisp) -> {
|
|
|
if(lisp.size() != 1) {
|
|
|
throw new LispError(LispError.ERR_NUM_ARG);
|
|
@@ -60,36 +62,6 @@ public class LispImpl implements Lisp {
|
|
|
}
|
|
|
return LispElement.generate(result);
|
|
|
});
|
|
|
- operators.put("cons", (lisp) -> {
|
|
|
- if(lisp.size() != 2) {
|
|
|
- throw new LispError(LispError.ERR_NUM_ARG);
|
|
|
- }
|
|
|
- ConsList<Object> cl;
|
|
|
- if(lisp.cdr().car() instanceof ConsList) {
|
|
|
- //Recup + evaluation de la liste
|
|
|
- cl = (ConsList<Object>) lisp.cdr().car();
|
|
|
- cl = ConsListFactory.parse(evaluateList(cl).toString());
|
|
|
- //Ajoute la valeur de gauche devant
|
|
|
- if(lisp.car() instanceof ConsList) {
|
|
|
- //Si la valeur gauche est aussi une liste on evalue sa valaue
|
|
|
- ConsList<Object> cltemp = (ConsList<Object>) lisp.car();
|
|
|
- cl = cl.prepend(evaluateList(cltemp).value);
|
|
|
- } else {
|
|
|
- cl = cl.prepend(lisp.car());
|
|
|
- }
|
|
|
- } else {
|
|
|
- LispElement le;
|
|
|
- if(lisp.car() instanceof ConsList) {
|
|
|
- //Si l'element est une liste on evalue sa valeur
|
|
|
- ConsList<Object> cltemp = (ConsList<Object>) lisp.car();
|
|
|
- le = evaluateList(cltemp);
|
|
|
- } else {
|
|
|
- le = LispElement.generate(lisp.car());
|
|
|
- }
|
|
|
- cl = ConsListFactory.asList(le + " . " + lisp.cdr().car());
|
|
|
- }
|
|
|
- return LispElement.generate(cl.toString());
|
|
|
- });
|
|
|
operators.put(">", (lisp) -> {
|
|
|
if(lisp.size() == 0) {
|
|
|
throw new LispError(LispError.ERR_NUM_ARG);
|
|
@@ -458,7 +430,7 @@ public class LispImpl implements Lisp {
|
|
|
* @throws LispError
|
|
|
*/
|
|
|
@SuppressWarnings("unchecked")
|
|
|
- private static LispElement getElement(Object elt) throws LispError {
|
|
|
+ public static LispElement getElement(Object elt) throws LispError {
|
|
|
if(elt instanceof ConsList) {
|
|
|
return evaluateList((ConsList<Object>) elt);
|
|
|
}
|