protected override Expression VisitMember(MemberExpression memberAccess) { if (ExpressionEvaluation.AreEquivalent(memberAccess, _sourceValue)) { ++_numberOfAccesses; } return(base.VisitMember(memberAccess)); }
public bool IsSameAs(IDataSource otherDataSource) { if (IsConditional && otherDataSource.IsConditional && ExpressionEvaluation.AreEqual(Condition, otherDataSource.Condition)) { return(true); } return(ExpressionEvaluation.AreEquivalent(otherDataSource.Value, _originalValue)); }
public void FixTest() { string expected = "(1 + 1)"; string actual = ExpressionEvaluation.Fix("1 + 1)"); Assert.AreEqual(expected, actual); string expectedTwo = "(((1 + 1) + (4 + 4) + (3 + 3) + 4) + 3)"; string actualTwo = ExpressionEvaluation.Fix("1 + 1) + 4 + 4) + 3 + 3) + 4) + 3)"); Assert.AreEqual(expectedTwo, actualTwo); }
public void EvaluateTest() { Assert.AreEqual(2, ExpressionEvaluation.Evaluate("(1 + 1)")); Assert.AreEqual(2, ExpressionEvaluation.Evaluate("(4 - 2)")); Assert.AreEqual(8, ExpressionEvaluation.Evaluate("(2 ^ 3)")); Assert.AreEqual(4, ExpressionEvaluation.Evaluate("(2 * 2)")); Assert.AreEqual(1, ExpressionEvaluation.Evaluate("(2 / 2)")); Assert.AreEqual(10, ExpressionEvaluation.Evaluate("(1 + 1) * ((5/5) * 5))")); Assert.AreEqual(8, ExpressionEvaluation.Evaluate("(((4 / 2) + 2) + 4)")); Assert.AreEqual(2, ExpressionEvaluation.Evaluate("(10 - 8)")); Assert.AreEqual(10, ExpressionEvaluation.Evaluate("(20 - 10)")); }
public bool IsSameAs(ConfiguredLambdaInfo otherLambdaInfo) { if (otherLambdaInfo == null) { return(false); } if ((_lambda.Body.NodeType == ExpressionType.Invoke) || (otherLambdaInfo._lambda.Body.NodeType == ExpressionType.Invoke)) { return(false); } return(ExpressionEvaluation.AreEquivalent(_lambda.Body, otherLambdaInfo._lambda.Body)); }
// This class is responsible to detect when any of the body vitals go out of limits public static bool vitalsAreOk(float bpm, float spo2, float respRate) { //True only when all the vitals is okay else false RangeChecker checkBPM = new RangeChecker(70, 150); RangeChecker checkSpO2 = new RangeChecker(90, 500); RangeChecker checkRespRate = new RangeChecker(30, 95); bool isOkayRespAndSpO2 = ExpressionEvaluation.evaluate(checkRespRate.checkRange(respRate), checkSpO2.checkRange(spo2)); if (isOkayRespAndSpO2 && checkBPM.checkRange(bpm)) { return(true); } return(false); }
public void Advance(object target, string expression) { if (!ExpressionEvaluation.IsMatch(expression)) { throw new ArgumentException(String.Format( System.Globalization.CultureInfo.CurrentCulture, Properties.Resources.ExpressionEvaluationService_InvalidReference, expression)); } // Don't process null targets. if (target == null) { return; } // If we find a null, we exit. for (Match segmentmatch = ExpressionEvaluation.Match(expression); segmentmatch.Success && target != null; segmentmatch = segmentmatch.NextMatch()) { // Catch all reflection-generated exceptions and throw the inner one. try { currentBinding = BindingFactory.CreateBinding(target, segmentmatch.Groups[GroupPart], segmentmatch.Groups[GroupParameters]); target = currentBinding.GetValue(); } catch (ArgumentException aex) { // Rethrow with a more meaningful message. throw new ArgumentException(String.Format( System.Globalization.CultureInfo.CurrentCulture, Properties.Resources.ExpressionEvaluationService_CantEvaluate, expression, segmentmatch.Value, aex.Message), aex); } catch (TargetInvocationException tiex) { // Rethrow with a more meaningful message. throw new ArgumentException(String.Format( System.Globalization.CultureInfo.CurrentCulture, Properties.Resources.ExpressionEvaluationService_CantEvaluate, expression, segmentmatch.Value, tiex.InnerException.Message), tiex); } } }
public bool Equals(ExpressionEvaluation other) { if (other == null) { return(false); } if (ReferenceEquals(other, this)) { return(true); } if (!Equals(other.Strategy, Strategy)) { return(false); } if (!Equals(other.Context, Context)) { return(false); } if (!Equals(other.EvaluationSteps, EvaluationSteps) && (other.EvaluationSteps == null || EvaluationSteps == null || !other.EvaluationSteps.SequenceEqual(EvaluationSteps))) { return(false); } if (other.StartTimestampMicroseconds != StartTimestampMicroseconds) { return(false); } if (other.EndTimestampMicroseconds != EndTimestampMicroseconds) { return(false); } if (other.NatvisValueId != NatvisValueId) { return(false); } return(true); }
private static bool TryAdjustToSingleUseableDataSource( ref IList <IDataSource> dataSources, IMemberMapperData mapperData) { var finalDataSource = dataSources.Last(); if (!finalDataSource.IsFallback) { return(false); } var finalValue = finalDataSource.Value; if (finalValue.NodeType == ExpressionType.Coalesce) { // Coalesce between the existing target member value and the fallback: dataSources[dataSources.Count - 1] = new AdHocDataSource( finalDataSource.SourceMember, ((BinaryExpression)finalValue).Right, finalDataSource.Condition, finalDataSource.Variables); return(false); } var targetMemberAccess = mapperData.GetTargetMemberAccess(); if (!ExpressionEvaluation.AreEqual(finalValue, targetMemberAccess)) { return(false); } if (dataSources.Count == 2) { return(true); } var dataSourcesWithoutFallback = new IDataSource[dataSources.Count - 1]; dataSourcesWithoutFallback.CopyFrom(dataSources); dataSources = dataSourcesWithoutFallback; return(false); }
public bool Equals(Expression x, Expression y) { if (x?.NodeType != ExpressionType.Call || y?.NodeType != ExpressionType.Call) { return(false); } var methodCallX = (MethodCallExpression)x; if (methodCallX.Method.IsStatic) { return(false); } var methodCallY = (MethodCallExpression)y; return((methodCallX.Method == methodCallY.Method) && (methodCallX.Object.NodeType == ExpressionType.Constant) && (methodCallY.Object.NodeType == ExpressionType.Constant) && ExpressionEvaluation.AreEqual(methodCallX.Object, methodCallY.Object)); }
private Expression GetFallbackValueOrNull() { var finalDataSource = _dataSources.Last(); var fallbackValue = finalDataSource.Value; if (finalDataSource.IsConditional || _dataSources.HasOne()) { return(fallbackValue); } if (fallbackValue.NodeType == ExpressionType.Coalesce) { return(((BinaryExpression)fallbackValue).Right); } var targetMemberAccess = MapperData.GetTargetMemberAccess(); if (ExpressionEvaluation.AreEqual(fallbackValue, targetMemberAccess)) { return(null); } return(fallbackValue); }
public EvaluationResult ExpressionEvaluation(string expression, params string[] definitions) { ExpressionEvaluation e = new ExpressionEvaluation(); return(e.EvaluateExpression(expression, GenerateDefines(definitions))); }
static void Main(string[] args) { // File paths const string DATA_PATH = "./Data/Project 2_INFO_5101.csv"; const string XML_PATH = "./Data/Project2_INFO_5101.xml"; // Load data List <Data> dataset = CSVFile.CSVDeserialize(DATA_PATH); // Print infix equations Console.WriteLine("\nSno \tInfix"); foreach (Data result in dataset) { Console.WriteLine(result.Sno + ":\t" + result.Infix); } // Convert to postfix and store it in the data and then print PostfixConversion post = new PostfixConversion(dataset); int count = 0; Console.WriteLine("\nSno \tPostfix"); foreach (string result in post.Convert()) { dataset[count].Postfix = result; Console.WriteLine(dataset[count].Sno + ":\t" + dataset[count].Postfix); count++; } // Convert to prefix and store it in the data and then print PrefixConversion pre = new PrefixConversion(dataset); count = 0; Console.WriteLine("\nSno \tPrefix"); foreach (string result in pre.Convert()) { dataset[count].Prefix = result; Console.WriteLine(dataset[count].Sno + ":\t" + dataset[count].Prefix); count++; } // Calculate postfix result and store it in the data and then print count = 0; Console.WriteLine("\nSno \tPostFix Results"); foreach (string result in ExpressionEvaluation.PostFixEvaluate(post.Convert())) { dataset[count].PostfixResult = result; Console.WriteLine(count + ":\t" + result); count++; } // Calculate prefix result and store it in the data and then print count = 0; Console.WriteLine("\nSno \tPrefix Results"); foreach (string result in ExpressionEvaluation.PrefixEvaluate(pre.Convert())) { dataset[count].PrefixResult = result; Console.WriteLine(count + ":\t" + result); count++; } // Display all results CompareExpressions ce = new CompareExpressions(); Console.WriteLine($"\nSno\t{"Infix",-20} {"Prefix",-17} {"Postfix",-17} {"Prefix Result",-15} {"Postfix Result",-15} {"Match",-15}"); foreach (Data d in dataset) { Console.WriteLine($"{d.Sno}\t{d.Infix,-20} {d.Prefix,-17} {d.Postfix,-17} {d.PrefixResult,-15} {d.PostfixResult,-15} {(ce.Compare(d.PrefixResult, d.PostfixResult) == 1 ? "True" : "False"),-15}"); } // Prompt user if they want to view the results in XML format ConsoleKey response; // Validation do { Console.Write("\nWould you like to view the results in XML format? [Y/N]:"); response = Console.ReadKey(false).Key; // true is intercept key (dont show), false is show if (response != ConsoleKey.Enter) { Console.WriteLine(); } } while (response != ConsoleKey.Y && response != ConsoleKey.N); // Generate XML if user selected yes, else don't if (response == ConsoleKey.Y) { Console.WriteLine("XML Generated!"); // Uses XMLExtensions using (StreamWriter outputFile = new StreamWriter(XML_PATH)) { outputFile.WriteStartDocument(); outputFile.WriteStartRootElement(); foreach (Data d in dataset) { outputFile.WriteStartElement(); outputFile.WriteAttribute("sno", d.Sno.ToString()); outputFile.WriteAttribute("infix", d.Infix); outputFile.WriteAttribute("prefix", d.Prefix); outputFile.WriteAttribute("postfix", d.Postfix); outputFile.WriteAttribute("evaluation", d.PostfixResult); outputFile.WriteAttribute("comparison", (ce.Compare(d.PrefixResult, d.PostfixResult) == 1 ? "True" : "False")); outputFile.WriteEndElement(); } outputFile.WriteEndRootElement(); } // Opens XML in Google Chrome browser Process.Start(@"cmd.exe ", @$ "/c start chrome {XML_PATH}"); } }
/// <summary> /// Evaluates the passed in arithmetic expression's validity. /// </summary> /// <param name="input"></param> /// <returns> /// bool /// </returns> public bool FunctionHandler(string input) { return(ExpressionEvaluation.StateMachine(input)); }