Open mingodad opened 3 years ago
Using this tool https://www.bottlecaps.de/convert/ and manually adding the tokens we can have a railroad diagram for the grammar at parse/gram.y.
parse/gram.y
Copy and paste the converted grammar shown bellow in https://www.bottlecaps.de/rr/ui on the TAB Edit Grammar then switch to the TAB View Diagram.
Edit Grammar
View Diagram
/* From https://github.com/oridb/mc/blob/master/parse/gram.y */ /* converted on Fri Aug 20, 2021, 08:34 (UTC+02) by bison-to-w3c v0.53 which is Copyright (c) 2011-2021 by Gunther Rademacher <grd@gmx.net> */ file ::= toplev ( Tendln toplev )* toplev ::= ( package | use | implstmt | traitdef | tydef | decl )? decl ::= attrs ( Tvar | Tconst | Tgeneric ) decllist traitspec attrs ::= Tattr* traitspec ::= ( Twith traitvar ( listsep traitvar )* )? traitvar ::= traitlist generictype ( Tret type )? traitlist ::= name ( listsep name )* decllist ::= declbody ( listsep declbody )* use ::= Tuse ( Tident | Tstrlit ) optident ::= Tident? package ::= Tpkg optident Tasn pkgitem ( Tendln pkgitem )* Tendblk pkgitem ::= ( decl | pkgtydef | traitdef | implstmt )? pkgtydef ::= attrs tydef declbody ::= declcore ( Tasn expr )? declcore ::= name | typedeclcore typedeclcore ::= name? Tcolon type name ::= Tident ( Tdot Tident )? implstmt ::= Timpl name type optauxtypes traitspec ( Tasn Tendln optendlns ( Tident Tasn exprln optendlns )* Tendblk )? traitdef ::= Ttrait Tident generictype optauxtypes traitspec ( Tasn optendlns ( Tident Tcolon type optendlns )* Tendblk )? optauxtypes ::= ( Tret typelist )? tydef ::= Ttype typeid traitspec ( Tasn type )? typeid ::= Tident ( Toparen generictype ( listsep generictype )* Tcparen )? type ::= structdef | tupledef | uniondef | compoundtype | generictype | Tellipsis generictype ::= Ttyparam compoundtype ::= functype | type ( Tosqbrac ( Tcolon | expr | Tellipsis ) Tcsqbrac | Tderef ) | name ( Toparen typelist Tcparen )? | Tvoidlit functype ::= Toparen funcsig Tcparen funcsig ::= typedeclcore? ( listsep typedeclcore )* Tret type tupledef ::= Toparen typelist Tcparen typelist ::= type ( listsep type )* structdef ::= Tstruct structent+ Tendblk structent ::= declcore? Tendln uniondef ::= Tunion unionelt+ Tendblk unionelt ::= ( Ttick name type? )? Tendln goto ::= Tgoto Tident retexpr ::= Tret? expr optexpr ::= expr? loopcond ::= exprln | Tendln optexprln ::= exprln | Tendln exprln ::= expr Tendln expr ::= ternexpr ( asnop ternexpr )* asnop ::= Tasn | Taddeq | Tsubeq | Tmuleq | Tdiveq | Tmodeq | Tboreq | Tbxoreq | Tbandeq | Tbsleq | Tbsreq ternexpr ::= lorexpr ( Tqmark lorexpr Tcolon lorexpr )? lorexpr ::= landexpr ( Tlor landexpr )* landexpr ::= cmpexpr ( Tland cmpexpr )* cmpexpr ::= borexpr ( cmpop borexpr )* cmpop ::= Teq | Tgt | Tlt | Tge | Tle | Tne borexpr ::= bandexpr ( ( Tbor | Tbxor ) bandexpr )* bandexpr ::= addexpr ( Tband addexpr )* addexpr ::= mulexpr ( addop mulexpr )* addop ::= Tplus | Tminus mulexpr ::= shiftexpr ( mulop shiftexpr )* mulop ::= Tmul | Tdiv | Tmod shiftexpr ::= prefixexpr ( shiftop prefixexpr )* shiftop ::= Tbsl | Tbsr prefixexpr ::= ( Tauto | Tinc | Tdec | Tband | Tlnot | Tbnot | Tminus | Tplus | Ttick name )* ( Ttick name | atomicexpr ( Tdot ( Tident | Tintlit ) | Tinc | Tdec | Tosqbrac ( expr | optexpr Tcolon optexpr ) Tcsqbrac | Tderef | Toparen expr? ( listsep expr )* Tcparen )* ) atomicexpr ::= Tident | Tgap | literal | ( Toparen expr ( Tcolon type )? | ( Tsizeof Toparen | Timpl Toparen name listsep ) type ) Tcparen tupbody ::= tuphead expr? ( listsep expr )* tuphead ::= expr listsep literal ::= funclit | littok | seqlit | tuplit tuplit ::= Toparen tupbody Tcparen littok ::= Tstrlit+ | Tchrlit | Tfloatlit | Tboollit | Tvoidlit | Tintlit obrace ::= Tobrace funclit ::= obrace params ( Tret type )? traitspec Tendln blkbody Tcbrace params ::= fnparam? ( listsep fnparam )* fnparam ::= declcore | Tgap ( Tcolon type )? seqlit ::= Tosqbrac optendlns ( arrayelt ( listsep arrayelt )* | structelt ( listsep structelt )* )? optcomma Tcsqbrac arrayelt ::= ( Tdot Tosqbrac expr Tcsqbrac Tasn )? expr optendlns structelt ::= Tdot Tident Tasn expr optendlns listsep ::= Tcomma optendlns optcomma ::= ( Tcomma optendlns )? optendlns ::= Tendln* stmt ::= ( goto | break | continue | retexpr | label | ifstmt | forstmt | whilestmt | matchstmt )? break ::= Tbreak continue ::= Tcontinue forstmt ::= Tfor ( ( optexprln | decl Tendln ) loopcond optexprln | expr Tcolon exprln ) block whilestmt ::= Twhile exprln block ifstmt ::= Tif exprln blkbody ( Telif exprln blkbody )* ( Telse block | Tendblk ) matchstmt ::= Tmatch exprln optendlns ( Tbor match )+ Tendblk match ::= expr Tcolon blkbody Tendln block ::= blkbody Tendblk blkbody ::= ( decl | stmt | tydef ) ( Tendln ( stmt | decl | tydef ) )* label ::= Tcolon Tident // Tokens Tplus ::= "+" Tminus ::= "-" Tmul ::= "*" Tdiv ::= "/" Tinc ::= "++" Tdec ::= "--" Tmod ::= "%" Tasn ::= "=" Taddeq ::= "+=" Tsubeq ::= "-=" Tmuleq ::= "*=" Tdiveq ::= "/=" Tmodeq ::= "%=" Tboreq ::= "|=" Tbxoreq ::= "^=" Tbandeq ::= "&=" Tbsleq ::= "<<=" Tbsreq ::= ">>=" Tbor ::= "|" Tbxor ::= "^" Tband ::= "&" Tbsl ::= "<<" Tbsr ::= ">>" Tbnot ::= "~" Teq ::= "==" Tgt ::= ">" Tlt ::= "<" Tge ::= ">=" Tle ::= "<=" Tne ::= "!=" Tlor ::= "||" Tland ::= "&&" Tlnot ::= "!" Tobrace ::= "{" Tcbrace ::= "}" Toparen ::= "(" Tcparen ::= ")" Tosqbrac ::= "[" Tcsqbrac ::= "]" Ttick ::= "`" Tderef ::= "#" Tqmark ::= "?" Ttype ::= "type" Tfor ::= "for" Twhile ::= "while" Tif ::= "if" Telse ::= "else" Telif ::= "else" Tmatch ::= "match" Tgoto ::= "goto" Tbreak ::= "break" Tcontinue ::= "continue" Tauto ::= "auto" Ttrait ::= "trait" //%token<tok> Timpl /* trait */ Tstruct ::= "struct" Tunion ::= "union" Ttyparam ::= "@typename" Tconst ::= "const" Tvar ::= "var" Tgeneric ::= "generic" Tgap ::= "_" Tellipsis ::= "..." Tendln ::= ";" Tendblk ::= ";;" Tcolon ::= ":" Twith ::= "::" Tdot ::= "." Tcomma ::= "," Tret ::= "->" Tuse ::= "use" Tpkg ::= "pkg" Tattr ::= "$attr" Tsizeof ::= "sizeof"
Using this tool https://www.bottlecaps.de/convert/ and manually adding the tokens we can have a railroad diagram for the grammar at
parse/gram.y
.Copy and paste the converted grammar shown bellow in https://www.bottlecaps.de/rr/ui on the TAB
Edit Grammar
then switch to the TABView Diagram
.