Esempio n. 1
0
 public UnitUniLeafMathNode(IMathNode inner, UnitTypes unitType, UnitConverter converter, Enum labelledUnit)
     : base(null)
 {
     this.Inner        = inner;
     this.unitType     = unitType;
     this.converter    = converter;
     this.labelledUnit = labelledUnit;
 }
Esempio n. 2
0
        public EvaluationTree(IMathNode root)
        {
            this.Root = root;
            if (this.Root == null)
            {
                this.Root = new NumericMathNode(0);
            }

            this.Root.Evaluate(); // I guess I need to do this once?
        }
Esempio n. 3
0
        public void Run()
        {
            while (true)
            {
                //ITokenizer tokenizer = new Tokenizer();
                Parser          parser = new Parser();
                List <FPTToken> tokens = new List <FPTToken>();

                Console.WriteLine("Enter code homie:");
                string userInput = Console.ReadLine();
                var    found     = userInput.Contains("plus");



                IMathNode result = parser.MathParse(userInput);
                Console.WriteLine(result.Evaluate());
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Create an operator node based on a character
        /// </summary>
        /// <param name="c">The operator being + - * / or ^</param>
        /// <param name="left">The left part of the operator</param>
        /// <param name="right">The right part of the operator</param>
        /// <returns>Valid operators return IMathNode, null if no operator</returns>
        public IMathNode CreateOperatorNode(string c, IMathNode left, IMathNode right)
        {
            switch (c)
            {
            case "+":
                return(new AdditionBiLeafMathNode(left, right));

            case "-":
                return(new SubtractionBiLeafMathNode(left, right));

            case "*":
                return(new MultiplicationBiLeafMathNode(left, right));

            case "/":
                return(new DivisionBiLeafMathNode(left, right));

            default:
                return(null);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Create an operator node based on a character
        /// </summary>
        /// <param name="c">The operator being + - * / or ^</param>
        /// <param name="left">The left part of the operator</param>
        /// <param name="right">The right part of the operator</param>
        /// <returns>Valid operators return IMathNode, null if no operator</returns>
        public IMathNode CreateOperatorNode(string c, IMathNode left, IMathNode right)
        {
            switch (c)
            {
            case "+":
                return(new AdditionBiLeafMathNode(left, right));

            case "-":
                return(new SubtractionBiLeafMathNode(left, right));

            case "*":
                return(new MultiplicationBiLeafMathNode(left, right));

            case "/":
                return(new DivisionBiLeafMathNode(left, right));

            case "^":
                return(new ExponentBiLeafMathNode(left, right));

            case "&":
                return(new BitwiseAndBiLeafMathNode(left, right));

            case "|":
                return(new BitwiseOrBiLeafMathNode(left, right));

            case "<<":
                return(new BitwiseShiftLeftBiLeafMathNode(left, right));

            case ">>":
                return(new BitwiseShiftRightBiLeafMathNode(left, right));

            case "%":
                return(new ModulusBiLeafMathNode(left, right));

            default:
                return(null);
            }
        }
Esempio n. 6
0
        private string read(string text, bool reporting, out IMathNode ast)
        {
            ast = null;

            IEnumerable <ITokenMatch <TokenEnum> > tokens = lexer.ScanText(text);

            ITokenMatch <TokenEnum> err_token = tokens.FirstOrDefault(it => it.Token == TokenEnum.Error);

            if (err_token != null)
            {
                return("Incorrect symbol in input: " + err_token.Text);
            }
            else
            {
                object root = parser.Parse(tokens, new ParserOptions()
                {
                    Trace = reporting
                }).FirstOrDefault();

                if (reporting)
                {
                    foreach (var s in parser.ParseLog)
                    {
                        Console.WriteLine(s + Environment.NewLine);
                    }
                }

                if (!parser.IsSuccessfulParse)
                {
                    return("There were errors while parsing." + Environment.NewLine + String.Join(Environment.NewLine, parser.ErrorMessages));
                }
                else
                {
                    ast = (IMathNode)root;
                    return(null);
                }
            }
        }
Esempio n. 7
0
 public SymbolMathNode(IMathNode left, IMathNode right, string symbol)
     : base(left, right, symbol)
 {
 }
Esempio n. 8
0
 public BitwiseAndBiLeafMathNode(IMathNode left, IMathNode right)
     : base(left, right, '&')
 {
 }
 public BitwiseShiftLeftBiLeafMathNode(IMathNode left, IMathNode right)
     : base(left, right, "<<")
 {
 }
Esempio n. 10
0
 public LogUniLeafMathNode(IMathNode logbase, IMathNode inner)
     : base(null)
 {
     this.Base  = logbase;
     this.Inner = inner;
 }
Esempio n. 11
0
 internal CosNode(IMathNode s)
 {
     this.sub = s;
 }
Esempio n. 12
0
 public SymbolMathNode(IMathNode left, IMathNode right, char symbol)
     : base(left, right, symbol)
 {
 }
Esempio n. 13
0
 internal SqrtNode(IMathNode s)
 {
     this.sub = s;
 }
 public BitwiseShiftRightBiLeafMathNode(IMathNode left, IMathNode right)
     : base(left, right, ">>")
 {
 }
Esempio n. 15
0
 public SubtractionBiLeafMathNode(IMathNode left, IMathNode right)
     : base(left, right, '-')
 {
 }
Esempio n. 16
0
 public ModulusBiLeafMathNode(IMathNode left, IMathNode right)
     : base(left, right, '%')
 {
 }
Esempio n. 17
0
 internal SinNode(IMathNode s)
 {
     this.sub = s;
 }
Esempio n. 18
0
 public Add(IMathNode m1, IMathNode m2)
 {
     this.m1 = m1;
     this.m2 = m2;
 }
Esempio n. 19
0
 public NegateUniLeafMathNode(IMathNode inner)
     : base(null)
 {
     this.Inner = inner;
 }
Esempio n. 20
0
 public DivisionBiLeafMathNode(IMathNode left, IMathNode right)
     : base(left, right, '/')
 {
 }
 public BitwiseOrBiLeafMathNode(IMathNode left, IMathNode right)
     : base(left, right, '|')
 {
 }
Esempio n. 22
0
 internal PowNode(IMathNode s1, IMathNode s2)
 {
     this.sub1 = s1;
     this.sub2 = s2;
 }
Esempio n. 23
0
 public BiLeafMathNode(IMathNode left, IMathNode right, object value)
 {
     this.left  = left;
     this.right = right;
     this.value = value;
 }
 public Add(IMathNode m1, IMathNode m2)
 {
     this.m1 = m1;
     this.m2 = m2;
 }
Esempio n. 25
0
 public MultiplicationBiLeafMathNode(IMathNode left, IMathNode right)
     : base(left, right, '*')
 {
 }
Esempio n. 26
0
 public ExponentBiLeafMathNode(IMathNode left, IMathNode right)
     : base(left, right, '^')
 {
 }
Esempio n. 27
0
 public AdditionBiLeafMathNode(IMathNode left, IMathNode right)
     : base(left, right, '+')
 {
 }
Esempio n. 28
0
 public StringMathNode(IMathNode inner)
 {
     this.value = inner;
 }
Esempio n. 29
0
 public SinhUniLeafMathNode(IMathNode inner)
     : base(null)
 {
     this.Inner = inner;
 }
Esempio n. 30
0
 /// <summary>
 /// Creates a new OperationNode, which represents a mathematical expression.
 /// The OperationNode contains the operation, and its branches are the operands.
 /// Each operand can be any node which inherits from MathNode and thus has an evaluate() function.
 /// </summary>
 /// <param name="op"></param>
 /// <param name="left"></param>
 /// <param name="right"></param>
 public OperatorNode(Operation op, IMathNode left, IMathNode right)
 {
     this.op    = op;
     this.left  = left ?? throw new NullReferenceException("Left branch of OperatorNode cannot be null.");
     this.right = right ?? throw new NullReferenceException("Right branch of OperatorNode cannot be null.");
 }