论坛首页 综合技术论坛

dot语言的BNF

浏览 2254 次
锁定老帖子 主题:dot语言的BNF
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2010-04-09  

最近在使用Graphviz工具作图,但是由于这个工具是C语言开发的,我打算把它移植到Java平台上,通过Java2D来渲染,绘制出静态的图片来。Graphviz的布局算法一大堆,也需要考虑移植过来。

 

Graphviz使用的一个DSL,即dot语言,看看了官方文档上附带的dot语言BNF,考虑使用javacc分析,这里是BNF代码:

graph -> [strict] (digraph|graph) id '{' stmt-list '}'
stmt-list -> [stmt [';'] [stmt-list] ]
stmt -> attr-stmt | node-stmt | edge-stmt | subgraph | id '=' id
attr-stmt -> (graph | node | edge) attr-list
attr-list -> '[' [a-list] ']' [attr-list]
a-list -> id '=' id [','][a-list]
node-stmt -> node-id [attr-list]
node-id -> id [port]
port -> port-location [port-angle] | port-angle [port-location]
port-location -> ':' id | ':' '(' id ',' id ')'
port-angle ->'@' id
edge-stmt -> (node-id | subgraph) edgeRHS [attr-list]
edgeRHS -> edgeop (node-id | subgraph) [edgeRHS]
subgraph -> [subgraph id] '{' stmt-list '}' | subgraph id

 

 

先贴在这里,后边在慢慢的编写词法/语法分析器,使用JavaCC应该没有多大的问题。

论坛首页 综合技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics