|
@@ -0,0 +1,61 @@
|
|
|
+package migl.lisp;
|
|
|
+
|
|
|
+public class LispImpl implements Lisp {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object parse(String expr) throws LispError {
|
|
|
+ /*
|
|
|
+ * Implementer Grammaire
|
|
|
+ * X = E | F
|
|
|
+ * E = bool | entier | decimal | string
|
|
|
+ * F = '('X*')'
|
|
|
+ */
|
|
|
+ // TODO Auto-generated method stub
|
|
|
+ String[] explode = this.explode(expr);
|
|
|
+ for(String str : explode) {
|
|
|
+ if(str.equals("(")){
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object evaluate(Object ex) throws LispError {
|
|
|
+ // TODO Auto-generated method stub
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param expr
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String[] explode(String expr) {
|
|
|
+ //Separe au niveau des espaces et des tabulations
|
|
|
+ String[] tmp = expr.split("[ |\t]");
|
|
|
+ //Compte le nombre de parenthese
|
|
|
+ int compteur = 0;
|
|
|
+ for(String str : tmp) {
|
|
|
+ if(str.charAt(0) == '(' || str.charAt(str.length() - 1) == ')') {
|
|
|
+ compteur++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //Creation du tableau de resultat
|
|
|
+ String[] result = new String[tmp.length + compteur];
|
|
|
+ int index = 0;
|
|
|
+ for(String str : tmp) {
|
|
|
+ if(str.charAt(0) == '(') {
|
|
|
+ result[index++] = "" + str.charAt(0);
|
|
|
+ result[index++] = str.substring(1);
|
|
|
+ } else if(str.charAt(str.length() - 1) == ')'){
|
|
|
+ result[index++] = str.substring(0, str.length() - 2);
|
|
|
+ result[index++] = "" + str.charAt(str.length() - 1);
|
|
|
+ } else {
|
|
|
+ result[index++] = str;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|