Esempio n. 1
0
 public SchemeType get(SchemeSymbol symbol)
 {
     if (_symbolTable.ContainsKey(symbol.value))
     {
         return _symbolTable[symbol.value];
     }
     else
     {
         return _parent.get(symbol);
     }
 }
Esempio n. 2
0
 public bool has(SchemeSymbol symbol)
 {
     if (_symbolTable.ContainsKey(symbol.value))
     {
         return true;
     }
     else
     {
         if (parent() == null)
         {
             return false;
         }
         else
         {
             return _parent.has(symbol);
         }
     }
 }
Esempio n. 3
0
        public void schemeEnvironentTest()
        {
            var root = SchemeEnvironmentRoot.instance;

            var testSymbol = new SchemeSymbol( "foo" );

            SchemeEnvironment e1 = new SchemeEnvironment( root );
            SchemeEnvironment e2 = new SchemeEnvironment( e1 );

            root.set( testSymbol, new SchemeInteger( 1 ) );

            Assert.AreEqual( root.get( testSymbol ), new SchemeInteger ( 1 ) );
            Assert.AreEqual( e1.get( testSymbol ), new SchemeInteger( 1 ) );
            Assert.AreEqual( e2.get( testSymbol ), new SchemeInteger( 1 ) );

            var e1foo = e1.get( testSymbol );

            Assert.IsTrue( ( (SchemeInteger) e1foo ).value == 1 );

            e2.set( testSymbol, new SchemeInteger( 2 ) );
            root.set( testSymbol, new SchemeInteger( 4 ) );

            Assert.IsTrue( e2.get( testSymbol ) != root.get( testSymbol ) );

            //test correctness in in evaluator

            var reader = new SchemeReader();
            var evaluator = new SchemeEvaluator();

            var ast = reader.parseString( "(define x 1)" );
            evaluator.evaluate( ast );

            ast = reader.parseString( "x" );
            Assert.AreEqual( evaluator.evaluate( ast )[0], new SchemeInteger( 1 ) );

            ast = reader.parseString( "(define bar (lambda () (define x 23) (x)))" );
            evaluator.evaluate( ast );

            ast = reader.parseString( "(bar)" );
            Assert.AreEqual( evaluator.evaluate( ast )[1], new SchemeInteger( 23 ) );

            ast = reader.parseString( "x" );
            Assert.AreEqual( evaluator.evaluate( ast )[0], new SchemeInteger( 1 ) );
        }
Esempio n. 4
0
 public void set(SchemeSymbol symbol, SchemeType type)
 {
     _symbolTable[symbol.value] = type;
 }
Esempio n. 5
0
 public bool has(SchemeSymbol symbol)
 {
     return _symbolTable.ContainsKey(symbol.value);
 }
Esempio n. 6
0
        public SchemeType get(SchemeSymbol symbol)
        {
            if (_symbolTable.ContainsKey(symbol.value))
            {
                return _symbolTable[symbol.value];
            }
            else
            {
                //check if it is an integer or float
                int intValue;
                if (int.TryParse(symbol.value, out intValue))
                {

                    return new SchemeInteger(intValue);
                }
                else
                {
                    return null;
                }
            }
        }
Esempio n. 7
0
        public void schemeObjectTest()
        {
            var object1 = new SchemeSymbol( "foo" );
            var object2 = new SchemeSymbol( "foo" );
            var object3 = new SchemeSymbol( "bar" );

            Assert.AreEqual( true, object1.Equals( object2 ) );
            Assert.AreEqual( true, object2.Equals( object1 ) );
            Assert.AreEqual( false, object1.Equals( object3 ) );
            //Assert.AreSame( object1, object2 );
        }