treeuse.m

来自「用YACC实现的一个小的编译工具」· M 代码 · 共 28 行

M
28
字号
// Use the Tree definitionwith treedef;// Define a function Sum that computes the sum// of the values of a all nodes of a given Tree tint Sum (Tree t){   match t {      rule node(v, l, r) :         return v + Sum(l) + Sum(r);      rule empty() :         return 0;   }}// The main functionextern "C" void printf(...);main (){   Tree ExampleTree = node(11, empty(), node(22, empty(), empty()));   printf ("Sum of ExampleTree is %d\n", Sum(ExampleTree));}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?