operators.ts 1.1 KB

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