123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- import { Types } from './../ast/types';
- import { Operators } from './../ast/operators';
- const InfixCompatibilityTable = Object.freeze([
- [Types.INTEGER, Types.REAL, Types.STRING],
- [Types.INTEGER, Types.REAL],
- [Types.INTEGER, Types.REAL],
- [Types.INTEGER, Types.REAL],
- [Types.INTEGER],
- [Types.INTEGER, Types.REAL],
- [Types.INTEGER, Types.REAL],
- [Types.INTEGER, Types.REAL],
- [Types.INTEGER, Types.REAL],
- [Types.INTEGER, Types.REAL, Types.STRING, Types.BOOLEAN],
- [Types.INTEGER, Types.REAL, Types.STRING, Types.BOOLEAN],
- [Types.BOOLEAN],
- [Types.BOOLEAN],
- null,
- ]);
- const UnaryCompatibilityTable = Object.freeze([
- [Types.INTEGER, Types.REAL],
- [Types.INTEGER, Types.REAL],
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- [Types.BOOLEAN],
- ]);
- export function canApplyUnaryOp (op, a) {
- const list = UnaryCompatibilityTable[op];
- if (!!!list) {
- return false;
- }
- const type = list.find(t => t === a.type);
- if (!!!type) {
- return false;
- }
- return true
- }
- export function canApplyInfixOp (op, a, b) {
- const list = InfixCompatibilityTable[op];
- if (!!!list) {
- return false;
- }
- const type = list.find(t => t === a.type);
- if (!!!type) {
- return false;
- }
- return type === b.type;
- }
|