Ejemplo n.º 1
0
        // parseList() `parses' special forms, constructs an appropriate
        // object of a subclass of Special, and stores a pointer to that
        // object in variable form.  It would be possible to fully parse
        // special forms at this point.  Since this causes complications
        // when using (incorrect) programs as data, it is easiest to let
        // parseList only look at the car for selecting the appropriate
        // object from the Special hierarchy and to leave the rest of
        // parsing up to the interpreter.
        private void parseList()
        {
            if (! car.isSymbol())
                form = new Regular();
            else
            {
                string name = car.getName();

                if (name.Equals("quote"))
                    form = new Quote();
                else if (name.Equals("lambda"))
                    form = new Lambda();
                else if (name.Equals("begin"))
                    form = new Begin();
                else if (name.Equals("if"))
                    form = new If();
                else if (name.Equals("let"))
                    form = new Let();
                else if (name.Equals("cond"))
                    form = new Cond();
                else if (name.Equals("define"))
                    form = new Define();
                else if (name.Equals("set!"))
                    form = new Set();
                else
                    form = new Regular();
            }
        }
Ejemplo n.º 2
0
 // parseList() `parses' special forms, constructs an appropriate
 // object of a subclass of Special, and stores a pointer to that
 // object in variable form.  It would be possible to fully parse
 // special forms at this point.  Since this causes complications
 // when using (incorrect) programs as data, it is easiest to let
 // parseList only look at the car for selecting the appropriate
 // object from the Special hierarchy and to leave the rest of
 // parsing up to the interpreter.
 void parseList()
 {
     if (car.isBool() || car.isNumber() || car.isString() || car.isNull() || car.isPair())
     {
         form = new Regular();
     }
     else if (car.isSymbol())
     {
         Ident specialSym = (Ident)car;
         if (specialSym.getName().Equals("quote"))
         {
             form = new Quote();
         }
         else if (specialSym.getName().Equals("lambda"))
         {
             form = new Lambda();
         }
         else if (specialSym.getName().Equals("begin"))
         {
             form = new Begin();
         }
         else if (specialSym.getName().Equals("if"))
         {
             form = new If();
         }
         else if (specialSym.getName().Equals("let"))
         {
             form = new Let();
         }
         else if (specialSym.getName().Equals("cond"))
         {
             form = new Cond();
         }
         else if (specialSym.getName().Equals("define"))
         {
             form = new Define();
         }
         else if (specialSym.getName().Equals("set"))
         {
             form = new Set();
         }
         else
         {
             form = new Regular();
         }
     }
 }
Ejemplo n.º 3
0
 // parseList() `parses' special forms, constructs an appropriate
 // object of a subclass of Special, and stores a pointer to that
 // object in variable form.  It would be possible to fully parse
 // special forms at this point.  Since this causes complications
 // when using (incorrect) programs as data, it is easiest to let
 // parseList only look at the car for selecting the appropriate
 // object from the Special hierarchy and to leave the rest of
 // parsing up to the interpreter.
 public void parseList()
 {
     if (car.isSymbol()) {
         string name = car.getName();
         if (name == "\'") { form = new Quote (true, true); }
         else if (String.Compare(name,  "quote", true) == 0) { form = new Quote(false, true); }
         else if (String.Compare(name, "lambda", true) == 0) { form = new Lambda (); }
         else if (String.Compare(name,  "begin", true) == 0) { form = new Begin (); }
         else if (String.Compare(name,     "if", true) == 0) { form = new If (); }
         else if (String.Compare(name,    "let", true) == 0) { form = new Let (); }
         else if (String.Compare(name,   "cond", true) == 0) { form = new Cond (); }
         else if (String.Compare(name, "define", true) == 0) { form = new Define(); }
         else if (String.Compare(name,   "set!", true) == 0) { form = new Set (); }
         else { form = new Regular(); }
     }
     else { form = new Regular(); }
 }
Ejemplo n.º 4
0
 // parseList() `parses' special forms, constructs an appropriate
 // object of a subclass of Special, and stores a pointer to that
 // object in variable form.  It would be possible to fully parse
 // special forms at this point.  Since this causes complications
 // when using (incorrect) programs as data, it is easiest to let
 // parseList only look at the car for selecting the appropriate
 // object from the Special hierarchy and to leave the rest of
 // parsing up to the interpreter.
 void parseList()
 {
     if (car.isSymbol())
     {
         switch (((Ident)car).getName())
         {
             case "begin":
                 form = new Begin();
                 break;
             case "cond":
                 form = new Cond();
                 break;
             case "let":
                 form = new Let();
                 break;
             case "define":
                 form = new Define();
                 break;
             case "if":
                 form = new If();
                 break;
             case "lambda":
                 form = new Lambda();
                 break;
             case "'":
                 form = new Quote();
                 break;
             case "set!":
                 form = new Set();
                 break;
             default:
                 form = new Regular();
                 break;
         }
     }
     else form = new Regular();
 }
Ejemplo n.º 5
0
 // parseList() `parses' special forms, constructs an appropriate
 // object of a subclass of Special, and stores a pointer to that
 // object in variable form.  It would be possible to fully parse
 // special forms at this point.  Since this causes complications
 // when using (incorrect) programs as data, it is easiest to let
 // parseList only look at the car for selecting the appropriate
 // object from the Special hierarchy and to leave the rest of
 // parsing up to the interpreter.
 void parseList()
 {
     // TODO: implement this function and any helper functions
     // you might need.
     if (!car.isSymbol())
     {
         form = new Regular();
         return;
     }
     switch ((car as Ident).GetName())
     {
         case "begin": form = new Begin();
             break;
         case "cond": form = new Cond();
             break;
         case "define": form = new Define();
             break;
         case "if": form = new If();
             break;
         case "lambda": form =  new Lambda();
             break;
         case "let": form = new Let();
             break;
         case "quote": form = new Quote();
             break;
         case "set": form = new Set();
             break;
         case "set!":
             goto case "set";
         default: form = new Regular();
             break;
     }
 }
Ejemplo n.º 6
0
 public void setForm(Special s)
 {
     form = s;
 }
Ejemplo n.º 7
0
        // parseList() `parses' special forms, constructs an appropriate
        // object of a subclass of Special, and stores a pointer to that
        // object in variable form.  It would be possible to fully parse
        // special forms at this point.  Since this causes complications
        // when using (incorrect) programs as data, it is easiest to let
        // parseList only look at the car for selecting the appropriate
        // object from the Special hierarchy and to leave the rest of
        // parsing up to the interpreter.
        void parseList()
        {
            // TODO: implement this function and any helper functions
            // you might need.

            if (car.isSymbol())
            {
                ident = ((Ident)car).ToString().ToUpper();

                switch (ident)
                {
                case "BEGIN":
                    form = new Begin();
                    break;

                case "COND":
                    form = new Cond();
                    break;

                case "DEFINE":
                    form = new Define();
                    break;

                case "IF":
                    form = new If();
                    break;

                case "LAMBDA":
                    form = new Lambda();
                    break;

                case "LET":
                    form = new Let();
                    break;

                case "'":
                    //Console.WriteLine("AMERICA FIN");
                    form = new Quote();
                    break;

                case "QUOTE":
                    //Console.WriteLine("ORAORAORAORAORAORAORAORAORA");
                    form = new Quote();
                    break;

                case "SET":
                    form = new Set();
                    break;

                case "SET!":
                    form = new Set();
                    break;

                default:
                    // Console.WriteLine("DORADORADORADORATHEEXPLORATHEEXPLORA");
                    form = new Regular();
                    break;
                }
            }
            else
            {
                //Console.WriteLine("FINISHED WITH THE LEMONLAIDE");
                form = new Regular();
            }
        }
Ejemplo n.º 8
0
 public Cons(Node a, Node d)
 {
     car  = a;
     cdr  = d;
     form = parseList();
 }
Ejemplo n.º 9
0
 public override void setFormToQuote(bool b, int d)
 {
     form = new Quote(b, d);
     if (car.isPair()) { car.setFormToQuote(b, d+1); }
     if (cdr.isPair()) { cdr.setFormToQuote(b, d);   }
 }
Ejemplo n.º 10
0
 public override void setForm(Special newForm)
 {
     form = newForm;
     if (car.isPair()) { car.setForm(newForm); }
     if (cdr.isPair()) { cdr.setForm(newForm); }
 }
Ejemplo n.º 11
0
 public override void setFormToRegular(bool b)
 {
     form = new Regular(true, b);
     if (car.isPair()) { car.setFormToRegular();  }
     if (cdr.isPair()) { cdr.setFormToRegular(b); }
 }
Ejemplo n.º 12
0
 // parseList() `parses' special forms, constructs an appropriate
 // object of a subclass of Special, and stores a pointer to that
 // object in variable form.  It would be possible to fully parse
 // special forms at this point.  Since this causes complications
 // when using (incorrect) programs as data, it is easiest to let
 // parseList only look at the car for selecting the appropriate
 // object from the Special hierarchy and to leave the rest of
 // parsing up to the interpreter.
 void parseList()
 {
     // TODO: implement this function and any helper functions
     // you might need.
     if(car.isSymbol())
     {
         switch(car.getName())
         {
             case "\'":
                 form = new Quote();
                 break;
             case "lambda":
                 form = new Lambda();
                 break;
             case "begin":
                 form = new Begin();
                 break;
             case "if":
                 form = new If();
                 break;
             case "let":
                 form = new Let();
                 break;
             case "cond":
                 form = new Cond();
                 break;
             case "define":
                 form = new Define();
                 break;
             case "set!":
                 form = new Set();
                 break;
             default:
                 form = new Regular();
                 break;
         }
     }
     else
     {
         form = new Regular();
     }
 }