利用EBNF生成Syntax/Railroad Diagram

有一个在线生成工具:http://railroad.my28msec.com/rr/ui

示例1:来自Stack Overflow

 

object ::= '{' ((string ':' value ) ( ',' string ':' value )*)? '}'


利用EBNF生成Syntax/Railroad Diagram

 


示例2:包含+, -, *,括号的算术表达式描述(EBNF)

 

exp     ::= term (addop term)*

term    ::= factor ('*' factor)*

addop   ::= '+'

         |'-'

factor  ::= '(' exp ')'

          |  [0-9]+


得到的Syntax/Railroad Diagram

 

exp:


exp ::= term ( addopterm )*

referenced by:factor


term:


term ::= factor ( '*' factor )*

referenced by:exp


addop:


addop ::= '+' | '-'
referenced by:exp

factor:
利用EBNF生成Syntax/Railroad Diagram
factor ::= '(' exp ')' | [0-9]+
referenced by:term

更多示例

 

你可能感兴趣的:(DI)