Files
BitwiseCmd/app/bitwise/expression.js
Borys Levytskyi e1963fb09c a lot of changes
2015-04-03 00:20:00 +03:00

23 lines
612 B
JavaScript

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