5 #include <AD/visualize/vcg.h>
8 // Visualize an expression tree
11 datatype Exp = INT int
15 where type Id = const char *
18 instantiate datatype Exp;
21 { if (V.visited(e)) return;
23 { INT i: { V.begin_node(e).label(i).color(VCG::lightyellow).end_node(e); }
24 | ID id: { V.begin_node(e).label(id).shape(VCG::box).color(VCG::pink).end_node(e); }
25 | BINOP(op,a,b): { V.begin_node(e).label(op).end_node(e).
29 | UNARYOP(op,a): { V.begin_node(e).label(op).end_node(e).edge(e,a);
38 const char * G = "A Sample Graph";
39 Exp e1 = BINOP("*",ID("z"),BINOP("+",ID("x"),ID("y")));
40 Exp e2 = BINOP("*",ID("z"),BINOP("+",ID("x"),ID("y")));
41 Exp e3 = BINOP("/",e1,BINOP("-",e2,INT(123)));
42 Exp e = UNARYOP("-",BINOP("+",e3,BINOP("+",ID("x"),ID("z"))));
44 V . begin_graph(G) . label(G) . display_edge_labels(true)
45 . layoutalgorithm(VCG::tree)
46 . xspace(50) . yspace(40)
48 . begin_node_default()
50 . color(VCG::lightgreen)
54 // Traverse expression
59 // translate it into GDL
63 ofstream TMP("./exp.vcg");
66 system("xvcg ./exp.vcg");