dooooooduo

JS expression eval tree

Mar 28th, 2016
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var str = "1+2.2*3.3";
  2. var numbers = str.match(/(\d+(?:\.\d+)?)/g);
  3. var signs = str.match(/[+\-*\/]/g);
  4. var priorities = {"+": 1, "-": 1, "*": 2, "/": 2};
  5. console.log(numbers);
  6. console.log(signs);
  7.  
  8. var EvalTree = function() {
  9.     this.left  = null;
  10.     this.right = null;
  11.     this.value = null;
  12.     this.add   = function(operandL, operandR, sign) {
  13.         this.
  14.     }
  15. };
  16.  
  17. var parseTree = new EvalTree();
  18.  
  19. var num = 0;
  20. priorities.sort(function(a, b) {
  21.     return b[1] - a[1];
  22. });
  23. for(var i in signs) {
  24.     if(signs[i] in prorities) {
Advertisement
Add Comment
Please, Sign In to add comment