mirror of
https://github.com/BorysLevytskyi/BitwiseCmd.git
synced 2025-12-15 01:12:47 +01:00
23 lines
612 B
JavaScript
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); |