// naive approach
var expr = { _type : "BoolExpr", _const : "And"
, values : [ { _type : "BoolExpr", _const : "True", values : {} }
, { _type : "BoolExpr", _const : "Or"
, values : [ { _type : "BoolExpr", _const : "False", values : {} }
, { _type : "BoolExpr", _const : "True", values : {} }
]
}
]
}
function view(expr) {
switch(expr._const){
case "True":
return "1";
case "False":
return "0";
case "And":
return "(" + view(expr.values[0]) + " /\\ " + view(expr.values[1]) + ")";
case "Or":
return "(" + view(expr.values[0]) + " \\/ " + view(expr.values[1]) + ")";
}
}
public
Authored by
Nick Yurchenko

Boolean expression AST traversal in JS
Edited
Please register or sign in to comment