Files
BitwiseCmd/app/bitwise/expression.js
Borys Levytskyi cadafab3ec huge regactoring
2015-04-02 22:53:06 +03:00

25 lines
654 B
JavaScript

(function(bitwise) {
var twoOperandsRegex = /^(\d+)(<<|>>|\||\&|\^)(\d+)$/;
app.service('expression', {
parse: function(string) {
var matches = twoOperandsRegex.exec(string);
if(matches == null) {
return null;
}
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);