コード例 #1
0
 /// <summary>
 /// Adds definitions from intersecting variable names, substituting their
 /// values into the context. Similar to running "Define" on the present
 /// context from each defined variable in the other context.
 /// </summary>
 /// <param name="other"></param>
 public void DefineFrom(VariableContext other)
 {
     foreach (var variableName in _initMap.Keys)
     {
         if (other.IsDefined(variableName))
         {
             Define(variableName, other.Get(variableName));
         }
     }
 }
コード例 #2
0
        public ISymbol ToValue(SymbolToken token)
        {
            if (token.Type != SymbolType.Number && token.Type != SymbolType.Variable)
            {
                throw new ArgumentException("Not a number", nameof(token));
            }

            if (token.Type == SymbolType.Variable)
            {
                return(_ctx.Get(token));
            }

            var s = token.Token;

            if (!s.Contains("."))
            {
                var i = int.Parse(s);
                return(new Number(i));
            }

            var f = double.Parse(s);

            return(new Number(f));
        }