bnfgen icon indicating copy to clipboard operation
bnfgen copied to clipboard

Grammar railroad diagram

Open mingodad opened this issue 3 years ago • 1 comments

I'm trying to get a railroad diagram using https://www.bottlecaps.de/rr/ui and converting manually the grammar at https://github.com/dmbaturin/bnfgen/blob/master/src/lib/bnf_parser.mly and the lexer at https://github.com/dmbaturin/bnfgen/blob/master/src/lib/bnf_lexer.mll and got so far the one bellow that can be copied and pasted at https://www.bottlecaps.de/rr/ui on the tab EditGrammar then click on the tab View Diagram.

grammar ::=  rules option EOF

rules ::=  /* empty */
	| rule
	| rules SEMI rule

rule ::=  nonterminal DEF rule_rhs //separated_pair

nonterminal ::=  IDENTIFIER

rule_rhs ::=  rule_rhs_part
	| rule_rhs OR rule_rhs_part

rule_rhs_part ::=  NUMBER? rule_rhs_symbols
	| rule_rhs_symbols

rule_rhs_symbols ::=  symbol
	| rule_rhs_symbols symbol

symbol ::=  terminal
	| nonterminal
	| symbol repeat_range

repeat_range ::=  LBRACE NUMBER RBRACE
	| LBRACE NUMBER COMMA NUMBER RBRACE

terminal ::=  STRING

// Tokens

DEF ::= "::="
OR ::= '|'
SEMI ::= ";"
LBRACE ::= '{'
RBRACE ::= '}'
COMMA ::= ','
IDENTIFIER ::= '<'  [a-zA-Z_]  [a-zA-Z_0-9]* '>'
NUMBER ::= [0-9]+
STRING ::= '"' [^"]* '"' | "'" [^']* "'"

mingodad avatar Aug 02 '21 07:08 mingodad

I did closed it as a mistake while deleting an incomplete comment.

mingodad avatar Aug 02 '21 11:08 mingodad