Files
BitwiseCmd/js/components/expression.js
Borys Levytskyi a628050e9c Initial Commit
2015-04-02 11:38:23 +03:00

20 lines
575 B
JavaScript

(function(bitwise) {
var twoOperandsRegex = /^(\d+)(<<|>>|\||\&|\^)(\d+)$/;
app.service('expression', {
parse: function(string) {
var matches = twoOperandsRegex.exec(string);
console.log(matches);
return {
string:matches[0],
operand1: parseInt(matches[1], 10),
sign: matches[2],
operand2: parseInt(matches[3], 10),
result: function() {
return eval(string);
}
}
}
});
})(window.app);