operators.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. export const Operators = Object.freeze({
  2. ADD: {ord: 0, value: "+"},
  3. SUB: {ord: 1, value: "-"},
  4. MULT: {ord: 2, value: '*'},
  5. DIV: {ord: 3, value: '/'},
  6. MOD: {ord: 4, value: '%'},
  7. GT: {ord: 5, value: '>'},
  8. GE: {ord: 6, value: '>='},
  9. LT: {ord: 7, value: '<'},
  10. LE: {ord: 8, value: '<='},
  11. EQ: {ord: 9, value: '=='},
  12. NEQ: {ord: 10, value: '!='},
  13. AND: {ord: 11, value: 'and'},
  14. OR: {ord: 12, value: 'or'},
  15. NOT: {ord: 13, value: 'not'}
  16. });
  17. export function convertFromString (op) {
  18. switch (op) {
  19. case '+' : return Operators.ADD;
  20. case '-' : return Operators.SUB;
  21. case '*' : return Operators.MULT;
  22. case '/' : return Operators.DIV;
  23. case '%' : return Operators.MOD;
  24. case '>' : return Operators.GT;
  25. case '>=' : return Operators.GE;
  26. case '<' : return Operators.LT;
  27. case '<=' : return Operators.LE;
  28. case '==' : return Operators.EQ;
  29. case '!=' : return Operators.NEQ;
  30. case 'and' : return Operators.AND;
  31. case 'or' : return Operators.OR;
  32. case 'not' : return Operators.NOT;
  33. }
  34. }