Exemplo n.º 1
0
 public Expression(string textOfCurrentLine)
 {
     this.input = textOfCurrentLine;
     Tokens = new Tokens(input);
     ReturnMessage = new ShuntingYard().ConvertToPostFixed(Tokens.AsList());
     if (ReturnMessage.Success == false) {
         failureMessage = ReturnMessage.Message;
     } else {
         PostFixedTokens = (List<Token>)ReturnMessage.ReturnValue;
         //Put postfixed Tokens into the tree
         foreach (Token t in PostFixedTokens) {
             ReturnMessage = ParseTree.AddToken(t);
             if (ReturnMessage.Success == false) {
                 failureMessage = ReturnMessage.Message;
             }
         }
     }
     //Set the outputString
     if (ReturnMessage.Success) {
         NumericalEvaluation = ParseTree.SetRoot().Evaluate();
         SystemLog.Add(NumericalEvaluation, LogObjectType.value);
         OutputString = NumericalEvaluation.ToString();
     } else {
         NumericalEvaluation = null;
         SystemLog.Add(failureMessage, LogObjectType.failureMessage);
         OutputString = failureMessage;
     }
 }
Exemplo n.º 2
0
 public void SetCurrentLine(string line)
 {
     lineNumber++;
     currentLine = line;
     Value = null;
     if(currentLine.Count() > 0){
         localExpression = new Expression(currentLine);
         if (localExpression.NumericalEvaluation != null) {
             Value = localExpression.NumericalEvaluation;
             OutputString = localExpression.OutputString;
         } else {
             OutputString = "\""+line+"\" " + localExpression.OutputString;
         }
     }
 }
Exemplo n.º 3
0
 static NumericalValue times(NumericalValue p1, NumericalValue p2)
 {
     return new NumericalValue(p1.AsDecimal() * p2.AsDecimal());
 }
Exemplo n.º 4
0
 static NumericalValue plus(NumericalValue p1, NumericalValue p2)
 {
     return new NumericalValue(p1.AsDecimal() + p2.AsDecimal());
 }
Exemplo n.º 5
0
 static NumericalValue power(NumericalValue p1, NumericalValue p2)
 {
     return new NumericalValue((decimal)Math.Pow((double)p1.AsDecimal(), (double)p2.AsDecimal()));
     //TODO: Handle all overflow exceptions
     //TODO: Catch overflow exceptions
     //Get a mathematics library that can do computations without overflow or divide by zero
     //Report to UI or save the value without evaluating
 }
Exemplo n.º 6
0
 static NumericalValue dividedBy(NumericalValue p1, NumericalValue p2)
 {
     return new NumericalValue(p1.AsDecimal() / p2.AsDecimal());
 }
Exemplo n.º 7
0
 public override void SetValue(LinkedList<Node> childrenToAdd)
 {
     if (childrenToAdd.Count != 2)
         throw new Exception("A two parameter operator must have two parameters");
     value = InfixOperators.GetOpInfo[this.op].Compute
         (childrenToAdd.Last().GetValue(), childrenToAdd.First().GetValue());
     Children = childrenToAdd;
 }
Exemplo n.º 8
0
 public NumberNode(NumericalValue val)
 {
     this.value = val;
 }
Exemplo n.º 9
0
 public NumberNode(double val)
 {
     this.value = new NumericalValue(val);
 }
Exemplo n.º 10
0
 public NumberNode(decimal val)
 {
     this.value = new NumericalValue(val);
 }