|
@@ -27,6 +27,16 @@ public class LispImpl implements Lisp {
|
|
|
}
|
|
|
return LispElement.generate(lisp.car().toString());
|
|
|
});
|
|
|
+ operators.put("if", (lisp) -> {
|
|
|
+ if(lisp.size() != 3) {
|
|
|
+ throw new LispError(LispError.ERR_NUM_ARG);
|
|
|
+ }
|
|
|
+ if(getElement(lisp.car()).toBoolean()) {
|
|
|
+ return getElement(lisp.cdr().car());
|
|
|
+ } else {
|
|
|
+ return getElement(lisp.cdr().cdr().car());
|
|
|
+ }
|
|
|
+ });
|
|
|
operators.put("not", (lisp) -> {
|
|
|
if(lisp.size() != 1) {
|
|
|
throw new LispError(LispError.ERR_NUM_ARG);
|
|
@@ -48,6 +58,12 @@ public class LispImpl implements Lisp {
|
|
|
boolean result = getElement(lisp.car()).toBoolean() || getElement(lisp.cdr().car()).toBoolean();
|
|
|
return LispElement.generate(result);
|
|
|
});
|
|
|
+ operators.put("cons", (lisp) -> {
|
|
|
+ if(lisp.size() != 2) {
|
|
|
+ throw new LispError(LispError.ERR_NUM_ARG);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ });
|
|
|
operators.put(">", (lisp) -> {
|
|
|
if(lisp.size() != 2) {
|
|
|
throw new LispError(LispError.ERR_NUM_ARG);
|
|
@@ -219,7 +235,7 @@ public class LispImpl implements Lisp {
|
|
|
* @return
|
|
|
*/
|
|
|
private boolean verifyList(String expr) {
|
|
|
- Pattern p = Pattern.compile("\\(([ |\t]*[A-Za-z0-9\\.\\+\\-\\/\\*<>=#]+[ |\t]*)+\\)");
|
|
|
+ Pattern p = Pattern.compile("\\(([ |\t]*[A-Za-z0-9\\.\\+\\-\\/\\*<>=#]+[ |\t]*)*\\)");
|
|
|
Matcher m = p.matcher(expr);
|
|
|
//Si pas de correspondance
|
|
|
if(!m.find()) {
|