packages/gerber-parser/lib/_parse-macro-expression.js
function(op, mods) {
    var getValue = function(t) {
      if (t[0] === '$') {
        return Number(mods[t])
      }
      return Number(t)
    }

    var type = op.type
    if (type === 'n') {
      return getValue(op.val)
    }
    if (type === '+') {
      return evaluate(op.left, mods) + evaluate(op.right, mods)
    }
    if (type === '-') {
      return evaluate(op.left, mods) - evaluate(op.right, mods)
    }
    if (type === 'x') {
      return evaluate(op.left, mods) * evaluate(op.right, mods)
    }
    // else division
    return evaluate(op.left, mods) / evaluate(op.right, mods)
  }
function(op, mods) {
    var getValue = function(t) {
      if (t[0] === '$') {
        return Number(mods[t])
      }
      return Number(t)
    }

    var type = op.type
    if (type === 'n') {
      return getValue(op.val)
    }
    if (type === '+') {
      return evaluate(op.left, mods) + evaluate(op.right, mods)
    }
    if (type === '-') {
      return evaluate(op.left, mods) - evaluate(op.right, mods)
    }
    if (type === 'x') {
      return evaluate(op.left, mods) * evaluate(op.right, mods)
    }
    // else division
    return evaluate(op.left, mods) / evaluate(op.right, mods)
  }
function ( op , mods ) { var getValue = function ( t ) { if ( t [ 0 ] === '$' ) { return Number ( mods [ t ] ) } return Number ( t ) } var type = op . type if ( type === 'n' ) { return getValue ( op . val ) } if ( type === '+' ) { return evaluate ( op . left , mods ) + evaluate ( op . right , mods ) } if ( type === '-' ) { return evaluate ( op . left , mods ) - evaluate ( op . right , mods ) } if ( type === 'x' ) { return evaluate ( op . left , mods ) * evaluate ( op . right , mods ) } // else division return evaluate ( op . left , mods ) / evaluate ( op . right , mods ) }
evalute by recursively traversing the tree
evalute by recursively traversing the tree