00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _BINOP_
00025 #define _BINOP_
00026
00027 #include "node.hh"
00028
00029 typedef const Node (*comp) (const Node& a, const Node& b);
00030 typedef bool (*pred) (const Node& a);
00031
00032 struct BinOp
00033 {
00034 const char* fName;
00035 const char* fNameVec;
00036 const char* fNameScal;
00037 comp fCompute;
00038 pred fLeftNeutral;
00039 pred fRightNeutral;
00040 int fPriority;
00041
00042 BinOp (const char* name, const char* namevec, const char* namescal, comp f, pred ln, pred rn, int priority)
00043 : fName(name), fNameVec(namevec), fNameScal(namescal), fCompute(f), fLeftNeutral(ln), fRightNeutral(rn), fPriority(priority) { }
00044
00045 Node compute(const Node& a, const Node& b) { return fCompute(a,b); }
00046
00047 bool isRightNeutral(const Node& a) { return fRightNeutral(a); }
00048 bool isLeftNeutral(const Node& a) { return fLeftNeutral(a); }
00049 };
00050
00051 extern BinOp* gBinOpTable[];
00052
00053
00054 enum {
00055 kAdd, kSub, kMul, kDiv, kRem,
00056 kLsh, kRsh,
00057 kGT, kLT, kGE, kLE, kEQ, kNE,
00058 kAND, kOR, kXOR
00059 };
00060
00061 #endif