rochus-keller / BUSY

BUSY is a lean, statically typed, cross-platform, easily bootstrappable build system for GCC, CLANG and MSVC inspired by Google GN
GNU General Public License v2.0
81 stars 6 forks source link

Grammar railroad diagram #2

Closed mingodad closed 1 year ago

mingodad commented 1 year ago

Using my fork of CocoR https://github.com/mingodad/CocoR-CPP to generate an EBNF understood by https://www.bottlecaps.de/rr/ui and manually adding the tokens from bslex.c we can have a nice navigable railroad diagram.

Copy and paste the EBNF shown bellow on https://www.bottlecaps.de/rr/ui on the tab Edit Grammar the click on the tab View Diagram to see/download a navigable railroad diagram.

//
// EBNF generated by CocoR parser generator to be viewed with https://www.bottlecaps.de/rr/ui
//

//
// productions
//

Busy ::=  ( ( Submodule | declaration | statement | macrodef ) ( T_Semi )? )*
Submodule ::=  ( T_submodule | T_submod | T_subdir ) identdef ( ( T_Eq | T_ColonEq ) ( T_path | T_ident ) )? ( T_else T_path )? ( T_Lpar paramList T_Rpar )?
declaration ::=  ( vardecl | typedecl )
statement ::=  ( condition | assigOrCall )
macrodef ::=  T_define identdef ( T_Lpar ( T_ident ( ( T_Comma )? T_ident )* )? T_Rpar )? body
typeref ::=  designator ( T_LbrackRbrack )?
designator ::=  ( T_Hat | T_Dot )? T_ident ( T_Dot T_ident )*
identdef ::=  T_ident ( T_Star | T_Minus | T_Bang )?
paramList ::=  paramValue ( ( T_Comma )? paramValue )*
paramValue ::=  T_ident ( ( T_Eq | T_ColonEq ) expression )?
expression ::=  SimpleExpression ( relation SimpleExpression )?
vardecl ::=  ( T_var | T_let | T_param ) identdef ( T_Colon typeref )? initializer
typedecl ::=  T_type identdef T_Eq ( enumdecl | classdecl )
body ::=  T_Lbrace ( ( Submodule | declaration | statement ) ( T_Semi )? )* T_Rbrace
initializer ::=  ( constructor | ( T_Eq | T_ColonEq ) expression )
enumdecl ::=  T_Lpar T_symbol ( T_Comma T_symbol )* T_Rpar
classdecl ::=  T_class ( T_Lpar designator T_Rpar )? ( T_Lbrace ( fielddecl ( T_Semi )? )* T_Rbrace | ( fielddecl ( T_Semi )? )* T_end )
fielddecl ::=  T_ident T_Colon typeref
ExpList ::=  expression ( ( T_Comma )? expression )*
SimpleExpression ::=  term ( AddOperator term )*
relation ::=  ( T_2Eq | T_BangEq | T_Lt | T_Leq | T_Gt | T_Geq | T_in )
term ::=  factor ( MulOperator factor )*
AddOperator ::=  ( T_Plus | T_Minus | T_2Bar )
factor ::=  ( T_integer | T_real | T_string | T_symbol | T_path | T_true | T_false | designator ( T_Lpar ExpList? T_Rpar )? | T_Lpar expression ( T_Qmark expression T_Colon expression )? T_Rpar | ( T_Plus | T_Minus | T_Bang ) factor | list )
MulOperator ::=  ( T_Star | T_Slash | T_2Amp | T_Percent )
list ::=  T_Lbrack ( expression ( ( T_Comma )? expression )* ( T_Comma )? )? T_Rbrack
constructor ::=  ( T_Lbrace block T_Rbrace | T_begin block T_end )
block ::=  ( ( declaration | statement ) ( T_Semi )? )*
condition ::=  T_if expression ( T_Lbrace block T_Rbrace ( T_else ( condition | T_Lbrace block T_Rbrace ) )? | T_then block ( T_elsif expression T_then block )* ( T_else block )? T_end )
assigOrCall ::=  designator ( assignment | call )
assignment ::=  ( T_Eq | T_ColonEq | T_PlusEq | T_MinusEq | T_StarEq ) expression
call ::=  T_Lpar ExpList T_Rpar

//
// tokens
//

//case Tok_\([^:]+\): return \("[^"]+"\);
T_Invalid ::= "<invalid>"
T_Bang ::= "!"
T_BangEq ::= "!="
T_Quote ::= '"'
T_Hash ::= "#"
T_2Hash ::= "##"
T_Dlr ::= "$"
T_Percent ::= "%"
T_Amp ::= "&"
T_2Amp ::= "&&"
T_Lpar ::= "("
T_Rpar ::= ")"
T_Star ::= "*"
T_Rcmt ::= "*/"
T_StarEq ::= "*="
T_Plus ::= "+"
T_PlusEq ::= "+="
T_Comma ::= ","
T_Minus ::= "-"
T_MinusEq ::= "-="
T_Dot ::= "."
T_Slash ::= "/"
T_Lcmt ::= "/*"
T_Colon ::= ":"
T_ColonEq ::= ":="
T_Semi ::= ";"
T_Lt ::= "<"
T_Leq ::= "<="
T_Eq ::= "="
T_2Eq ::= "=="
T_Gt ::= ">"
T_Geq ::= ">="
T_Qmark ::= "?"
T_Lbrack ::= "["
T_LbrackRbrack ::= "[]"
T_Rbrack ::= "]"
T_Hat ::= "^"
T_60 ::= "`"
T_Lbrace ::= "{"
T_2Bar ::= "||"
T_Rbrace ::= "}"
T_begin ::= "begin"
T_class ::= "class"
T_define ::= "define"
T_else ::= "else"
T_elsif ::= "elsif"
T_end ::= "end"
T_false ::= "false"
T_if ::= "if"
T_import ::= "import"
T_in ::= "in"
T_include ::= "include"
T_let ::= "let"
T_param ::= "param"
T_subdir ::= "subdir"
T_submod ::= "submod"
T_submodule ::= "submodule"
T_then ::= "then"
T_true ::= "true"
T_type ::= "type"
T_var ::= "var"
T_ident ::= "ident"
T_string ::= "string"
T_integer ::= "integer"
T_real ::= "real"
T_path ::= "path"
T_symbol ::= "symbol"
rochus-keller commented 1 year ago

That's cool, thanks for the hint.