Exemple #1
0
        public void TestWithSymbols()
        {
            var table       = new SymbolTable();
            var holder      = new SymbolHolder(table);
            var interpreter = new Interpreter("a=2+2", holder);

            interpreter.Interpret();

            Assert.True(table.HasSymbol("a"));
            Assert.Equal(4, holder.Get("a"));

            interpreter = new Interpreter("b=a+a", holder);
            interpreter.Interpret();
            Assert.True(table.HasSymbol("b"));
            Assert.Equal(8, holder.Get("b"));
        }
Exemple #2
0
 /// <summary>
 /// Verifies if there is a symbol and returns it value.
 /// </summary>
 /// <param name="symbolNode"></param>
 /// <returns></returns>
 public double VisitVar(SymbolNode symbolNode)
 {
     return(_symbolHolder.Get(symbolNode.Symbol.Name));
 }