Skip to content

Instantly share code, notes, and snippets.

@saswata-dutta
Last active April 12, 2019 16:09
Show Gist options
  • Save saswata-dutta/aeaf105908d83eea185f312c5c2cb711 to your computer and use it in GitHub Desktop.
Save saswata-dutta/aeaf105908d83eea185f312c5c2cb711 to your computer and use it in GitHub Desktop.
function unary(type, rhs) {
return {
type : type,
rhs: rhs
};
}
function binary(type, lhs, rhs) {
return {
type : type,
lhs: lhs,
rhs: rhs
};
}
function S_EQ(lhs, rhs) {
return binary("STR_EQUALS", lhs, rhs);
}
function S_NE(lhs, rhs) {
return binary("STR_NOT_EQUALS", lhs, rhs);
}
function EQ(lhs, rhs) {
return binary("EQUALS", lhs, rhs);
}
function NE(lhs, rhs) {
return binary("NOT_EQUALS", lhs, rhs);
}
function LT(lhs, rhs) {
return binary("LESSER_THAN", lhs, rhs);
}
function LE(lhs, rhs) {
return binary("LESSER_THAN_EQ", lhs, rhs);
}
function GT(lhs, rhs) {
return binary("GREATER_THAN", lhs, rhs);
}
function GE(lhs, rhs) {
return binary("GREATER_THAN_EQ", lhs, rhs);
}
function L_AND(rhs) {
return unary("NARY_AND", rhs);
}
function L_OR(rhs) {
return unary("NARY_OR", rhs);
}
function NOT(rhs) {
return unary("NOT", rhs);
}
function AND(lhs, rhs) {
return binary("AND", lhs, rhs);
}
function OR(lhs, rhs) {
return binary("OR", lhs, rhs);
}
function ADD(lhs, rhs) {
return binary("ADD", lhs, rhs);
}
function SUB(lhs, rhs) {
return binary("SUBTRACT", lhs, rhs);
}
function MUL(lhs, rhs) {
return binary("MULTIPLY", lhs, rhs);
}
function DIV(lhs, rhs) {
return binary("DIVIDE", lhs, rhs);
}
function IF(cond, lhs, rhs) {
return {
type: "IF",
cond: cond,
lhs: lhs,
rhs: rhs
};
}
function literal(type, value) {
return {
type: type,
value: value
};
}
function STR(value) {
return literal("STR_LITERAL", value);
}
function NUM(value) {
return literal("NUM_LITERAL", value);
}
function symbol(type, key) {
return {
type: type,
key: key
};
}
function BOOL_VAR(key) {
return symbol("BOOL_SYMBOL",key);
}
function STR_VAR(key) {
return symbol("STR_SYMBOL",key);
}
function NUM_VAR(key) {
return symbol("NUM_SYMBOL",key);
}
function SET(key) {
return symbol("STR_SET_SYMBOL",key);
}
function CONTAINS(lhs, rhs) {
return binary("STR_SET_CONTAINS", lhs, rhs);
}
function MIN(lhs, rhs) {
return binary("MIN", lhs, rhs);
}
function MAX(lhs, rhs) {
return binary("MAX", lhs, rhs);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment