Ejemplo n.º 1
0
        public static ISymbol ToExpression(string expressionString, VariableContext context)
        {
            var tokens = Parse(expressionString, context);
            var tb     = new TreeBuilder(tokens, context);

            return(tb.Parse());
        }
Ejemplo n.º 2
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));
         }
     }
 }
Ejemplo n.º 3
0
        public static List <SymbolToken> Parse(string expression, VariableContext context)
        {
            var pipe1 = new StringToPrimitiveTokenPipe(expression, context);
            var pipe2 = new MatchAllParenthesesProcessor(pipe1);
            var pipe3 = new NegationProcessor(pipe2);
            var pipe4 = new RedundantParenthesesProcessor(pipe3);
            var pipe5 = new TokenValidater(pipe4);

            return(pipe5.PumpAll());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Identifies whether all variables in this context are
        /// registered in the other context
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public bool IsSubsetOf(VariableContext other)
        {
            foreach (var variableName in _initMap.Keys)
            {
                if (!other.IsRegistered(variableName))
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 5
0
        public TreeBuilder(List <SymbolToken> tokens, VariableContext ctx)
        {
            _tokens = TrimParentheses(tokens);
            if (_tokens.Count == 0)
            {
                throw new ArgumentException("missing token", nameof(tokens));
            }

            if (_tokens.Count == 1 && !_tokens[0].Type.IsValue())
            {
                throw new ArgumentException(string.Format("hanging token: {0}", tokens[0].Token),
                                            nameof(tokens));
            }

            _ctx = ctx;
        }
Ejemplo n.º 6
0
 public AlgebraProcessor(VariableContext context = null)
 {
     _variableContext = context ?? VariableContext.Default;
 }
 public StringToPrimitiveTokenPipe(IEnumerable <char> input, VariableContext ctx) : base(input)
 {
     _chars = new StringBuilder();
     _ctx   = ctx;
 }
 public StringToPrimitiveTokenPipe(string input, VariableContext ctx) : this(input.ToCharArray(), ctx)
 {
 }