如何使用Graphviz创建正确的语法图?

问题描述 投票:2回答:1

我正在尝试使用Graphviz(最终将嵌入在Sphinx中)重新创建以下语法图:

enter image description here

使用DOT语言,定义了下图:

digraph numexpr {

    bgcolor="transparent"

    {rank = same;
    p_0[shape=point];
    n_1[shape=block, label="constant", group=g1];
    p_1[shape=point]}

    n_2[shape=block, label="enumerated-list", group=g1]
    n_3[shape=block, label="reference", group=g1]
    n_4[shape=block, label="function-call", group=g1]
    n_5[shape=block, label="operator-expression", group=g1]
    n_6[shape=block, label="iterative-expression", group=g1]
    n_7[shape=block, label="conditional-expression", group=g1]
    n_8[shape=block, label="logical-expression", group=g1]

    {rank = same;
    c_1[shape=circle, label="("];
    n_9[shape=block, label="numerical-expression", group=g1];
    c_2[shape=circle, label=")"]}

    p_0 -> n_1 [arrowsize=.5]
    p_0 -> n_2 [arrowsize=.5]
    p_0 -> n_3 [arrowsize=.5]
    p_0 -> n_4 [arrowsize=.5]
    p_0 -> n_5 [arrowsize=.5]
    p_0 -> n_6 [arrowsize=.5]
    p_0 -> n_7 [arrowsize=.5]
    p_0 -> n_8 [arrowsize=.5]
    p_0 -> c_1 [arrowsize=.5]
    c_1 -> n_9 [arrowsize=.5]
    n_1 -> p_1 [arrowsize=.5]
    n_2 -> p_1 [arrowsize=.5]
    n_3 -> p_1 [arrowsize=.5]
    n_4 -> p_1 [arrowsize=.5]
    n_5 -> p_1 [arrowsize=.5]
    n_6 -> p_1 [arrowsize=.5]
    n_7 -> p_1 [arrowsize=.5]
    n_8 -> p_1 [arrowsize=.5]
    n_9 -> c_2 [arrowsize=.5]
    c_2 -> p_1 [arrowsize=.5]

    edge[style=invis];
    n_1 -> n_2
    n_2 -> n_3
    n_3 -> n_4
    n_4 -> n_5
    n_5 -> n_6
    n_6 -> n_7
    n_7 -> n_8
    n_8 -> n_9

}

呈现如下:

enter image description here

关闭,但没有雪茄。如何操纵边缘,使渲染看起来与原始语法图更相似?

graphviz diagram dot
1个回答
1
投票
这里是一个近似值。完成约225行<< dot>代码并需要三步过程:

dot -Tdot ...> somefile

    手动编辑某文件以添加18个水平边缘并添加layout = neato
  1. dot -Tpng somefile> somefile.png
  2. enter image description here
  • 如果必须再次执行,则将为节点和边生成

    pos

    值。
  • © www.soinside.com 2019 - 2024. All rights reserved.