コード例 #1
0
ファイル: Expression.cs プロジェクト: Amichai/OpenPadProject
 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;
     }
 }
コード例 #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;
         }
     }
 }
コード例 #3
0
 static NumericalValue times(NumericalValue p1, NumericalValue p2)
 {
     return new NumericalValue(p1.AsDecimal() * p2.AsDecimal());
 }
コード例 #4
0
 static NumericalValue plus(NumericalValue p1, NumericalValue p2)
 {
     return new NumericalValue(p1.AsDecimal() + p2.AsDecimal());
 }
コード例 #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
 }
コード例 #6
0
 static NumericalValue dividedBy(NumericalValue p1, NumericalValue p2)
 {
     return new NumericalValue(p1.AsDecimal() / p2.AsDecimal());
 }
コード例 #7
0
ファイル: ParseTree.cs プロジェクト: Amichai/OpenPadProject
 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;
 }
コード例 #8
0
ファイル: ParseTree.cs プロジェクト: Amichai/OpenPadProject
 public NumberNode(NumericalValue val)
 {
     this.value = val;
 }
コード例 #9
0
ファイル: ParseTree.cs プロジェクト: Amichai/OpenPadProject
 public NumberNode(double val)
 {
     this.value = new NumericalValue(val);
 }
コード例 #10
0
ファイル: ParseTree.cs プロジェクト: Amichai/OpenPadProject
 public NumberNode(decimal val)
 {
     this.value = new NumericalValue(val);
 }