Browse Source

Ajout quote

Arthur Brandao 6 years ago
parent
commit
913aa9582e
1 changed files with 18 additions and 10 deletions
  1. 18 10
      src/migl/lisp/LispImpl.java

+ 18 - 10
src/migl/lisp/LispImpl.java

@@ -13,64 +13,72 @@ import migl.util.ConsListFactory;
 
 public class LispImpl implements Lisp {
 	
+	
+	
 	/**
 	 * Les operateurs gérés par l'interpréteur
 	 */
 	private static Map<String, LispOperator> operators = new HashMap<>();
 	static {
 		//Définition des opérateurs
+		operators.put("quote", (lisp) -> {
+			if(lisp.size() != 1) {
+				throw new LispError(LispError.ERR_NUM_ARG);
+			}
+			return LispElement.generate(lisp.car().toString());
+		});
 		operators.put("not", (lisp) -> {
 			if(lisp.size() != 1) {
-				throw new LispError("Incorrect number of argument");
+				throw new LispError(LispError.ERR_NUM_ARG);
 			}
 			boolean result = !getElement(lisp.car()).toBoolean();
 			return LispElement.generate(result);
 		});
 		operators.put("and", (lisp) -> {
 			if(lisp.size() != 2) {
-				throw new LispError("Incorrect number of argument");
+				throw new LispError(LispError.ERR_NUM_ARG);
 			}
 			boolean result = getElement(lisp.car()).toBoolean() && getElement(lisp.cdr().car()).toBoolean();
 			return LispElement.generate(result);
 		});
 		operators.put("or", (lisp) -> {
 			if(lisp.size() != 2) {
-				throw new LispError("Incorrect number of argument");
+				throw new LispError(LispError.ERR_NUM_ARG);
 			}
 			boolean result = getElement(lisp.car()).toBoolean() || getElement(lisp.cdr().car()).toBoolean();
 			return LispElement.generate(result);
 		});
 		operators.put(">", (lisp) -> {
 			if(lisp.size() != 2) {
-				throw new LispError("Incorrect number of argument");
+				throw new LispError(LispError.ERR_NUM_ARG);
 			}
 			boolean result = getElement(lisp.car()).toNumber() > getElement(lisp.cdr().car()).toNumber();
 			return LispElement.generate(result);
 		});
 		operators.put(">=", (lisp) -> {
 			if(lisp.size() != 2) {
-				throw new LispError("Incorrect number of argument");
+				throw new LispError(LispError.ERR_NUM_ARG);
 			}
 			boolean result = getElement(lisp.car()).toNumber() >= getElement(lisp.cdr().car()).toNumber();
 			return LispElement.generate(result);
 		});
 		operators.put("<", (lisp) -> {
 			if(lisp.size() != 2) {
-				throw new LispError("Incorrect number of argument");
+				throw new LispError(LispError.ERR_NUM_ARG);
 			}
 			boolean result = getElement(lisp.car()).toNumber() < getElement(lisp.cdr().car()).toNumber();
 			return LispElement.generate(result);
 		});
 		operators.put("<=", (lisp) -> {
 			if(lisp.size() != 2) {
-				throw new LispError("Incorrect number of argument");
+				throw new LispError(LispError.ERR_NUM_ARG);
 			}
 			boolean result = getElement(lisp.car()).toNumber() <= getElement(lisp.cdr().car()).toNumber();
 			return LispElement.generate(result);
 		});
 		operators.put("=", (lisp) -> {
 			if(lisp.size() != 2) {
-				throw new LispError("Incorrect number of argument");
+				throw new LispError(LispError.ERR_NUM_ARG);
 			}
 			boolean result = getElement(lisp.car()).toNumber() == getElement(lisp.cdr().car()).toNumber();
 			return LispElement.generate(result);
@@ -131,12 +139,12 @@ public class LispImpl implements Lisp {
 					}
 					return LispElement.generate(elt1.toInt().subtract(elt2.toInt()));
 				default:
-					throw new LispError("Incorrect number of argument");
+					throw new LispError(LispError.ERR_NUM_ARG);
 			}
 		});
 		operators.put("/", (lisp) -> {
 			if(lisp.size() != 2) {
-				throw new LispError("Incorrect number of argument");
+				throw new LispError(LispError.ERR_NUM_ARG);
 			}
 			LispElement elt1 = getElement(lisp.car());
 			LispElement elt2 = getElement(lisp.cdr().car());