grame-cncm / faust

Functional programming language for signal processing and sound synthesis
http://faust.grame.fr
Other
2.59k stars 324 forks source link

Grammar railroad diagram #876

Open mingodad opened 1 year ago

mingodad commented 1 year ago

Using some online tools like https://www.bottlecaps.de/rr/ui and https://www.bottlecaps.de/convert/ and manually adding the tokens from the lexer 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.

/* converted on Fri Mar 31, 2023, 18:28 (UTC+02) by bison-to-w3c v0.64 which is Copyright (c) 2011-2023 by Gunther Rademacher <grd@gmx.net> */
//From https://github.com/grame-cncm/faust/blob/master-dev/compiler/parser/faustparser.y

program  ::= stmtlist
stmtlist ::= ( variantlist statement )*
deflist  ::= ( variantlist definition )*
variantlist
         ::= variant*
variant  ::= FLOATMODE
           | DOUBLEMODE
           | QUADMODE
           | FIXEDPOINTMODE
reclist  ::= recinition*
number   ::= ( ADD | SUB )? ( INT | FLOAT )
statement
         ::= ( IMPORT LPAR uqstring RPAR | DECLARE name name? string ) ENDDEF
           | definition
           | BDOC docelem* EDOC
docelem  ::= DOCCHAR*
           | doceqn
           | docdgm
           | docntc
           | doclst
           | docmtd
doceqn   ::= BEQN expression EEQN
docdgm   ::= BDGM expression EDGM
docntc   ::= NOTICE
doclst   ::= BLST lstattrdef* ELST
lstattrdef
         ::= ( LSTDEPENDENCIES | LSTMDOCTAGS | LSTDISTRIBUTED ) LSTEQ LSTQ lstattrval LSTQ
lstattrval
         ::= LSTTRUE
           | LSTFALSE
docmtd   ::= BMETADATA name EMETADATA
definition
         ::= ( defname ( LPAR arglist RPAR )? DEF expression | error ) ENDDEF
recinition
         ::= ( recname DEF expression | error ) ENDDEF
defname  ::= ident
recname  ::= DELAY1 ident
expression
         ::= expression ( ( WITH LBRAQ deflist | LETREC LBRAQ reclist ( WHERE deflist )? ) RBRAQ | ( PAR | SEQ | SPLIT | MIX | REC ) expression )
           | infixexp
infixexp ::= infixexp ( ( ADD | SUB | MUL | DIV | MOD | POWOP | FDELAY | AND | OR | XOR | LSH | RSH | LT | LE | GT | GE | EQ | NE ) infixexp | DELAY1 | DOT ident | LPAR arglist RPAR | LCROC deflist RCROC )
           | primitive
primitive
         ::= INT
           | FLOAT
           | ADD INT
           | ADD FLOAT
           | SUB INT
           | SUB FLOAT
           | WIRE
           | CUT
           | MEM
           | PREFIX
           | INTCAST
           | FLOATCAST
           | ADD
           | SUB
           | MUL
           | DIV
           | MOD
           | FDELAY
           | AND
           | OR
           | XOR
           | LSH
           | RSH
           | LT
           | LE
           | GT
           | GE
           | EQ
           | NE
           | ATTACH
           | ENABLE
           | CONTROL
           | ACOS
           | ASIN
           | ATAN
           | ATAN2
           | COS
           | SIN
           | TAN
           | EXP
           | LOG
           | LOG10
           | POWOP
           | POWFUN
           | SQRT
           | ABS
           | MIN
           | MAX
           | FMOD
           | REMAINDER
           | FLOOR
           | CEIL
           | RINT
           | RDTBL
           | RWTBL
           | SELECT2
           | SELECT3
           | ASSERTBOUNDS
           | LOWEST
           | HIGHEST
           | ident
           | SUB ident
           | LPAR expression RPAR
           | LAMBDA LPAR ident ( PAR ident )* RPAR DOT LPAR expression RPAR
           | CASE LBRAQ rule+ RBRAQ
           | ffunction
           | fconst
           | fvariable
           | COMPONENT LPAR uqstring RPAR
           | LIBRARY LPAR uqstring RPAR
           | ENVIRONMENT LBRAQ stmtlist RBRAQ
           | WAVEFORM LBRAQ number ( PAR number )* RBRAQ
           | ROUTE LPAR argument PAR argument RPAR
           | ROUTE LPAR argument PAR argument PAR expression RPAR
           | button
           | checkbox
           | vslider
           | hslider
           | nentry
           | vgroup
           | hgroup
           | tgroup
           | vbargraph
           | hbargraph
           | soundfile
           | fpar
           | fseq
           | fsum
           | fprod
           | finputs
           | foutputs
ident    ::= IDENT
name     ::= IDENT
arglist  ::= argument ( PAR argument )*
argument ::= argument ( SEQ | SPLIT | MIX | REC ) argument
           | infixexp
string   ::= STRING
uqstring ::= STRING
fstring  ::= STRING
           | FSTRING
fpar     ::= IPAR LPAR ident PAR argument PAR expression RPAR
fseq     ::= ISEQ LPAR ident PAR argument PAR expression RPAR
fsum     ::= ISUM LPAR ident PAR argument PAR expression RPAR
fprod    ::= IPROD LPAR ident PAR argument PAR expression RPAR
finputs  ::= INPUTS LPAR expression RPAR
foutputs ::= OUTPUTS LPAR expression RPAR
ffunction
         ::= FFUNCTION LPAR signature PAR fstring PAR string RPAR
fconst   ::= FCONSTANT LPAR type name PAR fstring RPAR
fvariable
         ::= FVARIABLE LPAR type name PAR fstring RPAR
button   ::= BUTTON LPAR uqstring RPAR
checkbox ::= CHECKBOX LPAR uqstring RPAR
vslider  ::= VSLIDER LPAR uqstring PAR argument PAR argument PAR argument PAR argument RPAR
hslider  ::= HSLIDER LPAR uqstring PAR argument PAR argument PAR argument PAR argument RPAR
nentry   ::= NENTRY LPAR uqstring PAR argument PAR argument PAR argument PAR argument RPAR
vgroup   ::= VGROUP LPAR uqstring PAR expression RPAR
hgroup   ::= HGROUP LPAR uqstring PAR expression RPAR
tgroup   ::= TGROUP LPAR uqstring PAR expression RPAR
vbargraph
         ::= VBARGRAPH LPAR uqstring PAR argument PAR argument RPAR
hbargraph
         ::= HBARGRAPH LPAR uqstring PAR argument PAR argument RPAR
soundfile
         ::= SOUNDFILE LPAR uqstring PAR argument RPAR
signature
         ::= type fun ( OR fun ( OR fun ( OR fun )? )? )? LPAR typelist? RPAR
fun      ::= IDENT
typelist ::= argtype ( PAR argtype )*
rule     ::= LPAR arglist RPAR ARROW expression ENDDEF
type     ::= INTCAST
           | FLOATCAST
argtype  ::= INTCAST
           | FLOATCAST
           | NOTYPECAST

// Tokens

BDOC ::= "<mdoc>"
//<doc>.                          return DOCCHAR; /* char by char, may be slow ?? */
//<doc>\n                         return DOCCHAR; /* keep newline chars */
NOTICE ::= "<notice/>"
NOTICE ::= "<notice />"
BLST ::= "<listing"
BEQN ::= "<equation>"
EEQN ::= "</equation>"
BDGM ::= "<diagram>"
EDGM ::= "</diagram>"
BMETADATA ::= "<metadata>"
EMETADATA ::= "</metadata>"
EDOC ::= "</mdoc>"

LSTTRUE ::= "true"
LSTFALSE ::= "false"
LSTDEPENDENCIES ::= "dependencies"
LSTMDOCTAGS ::= "mdoctags"
LSTDISTRIBUTED ::= "distributed"
LSTEQ ::= "="
LSTQ ::= '"'
ELST ::= "/>"

//\("[^"]+"\)\s+return \([^;]+\);
SEQ ::= ":"
PAR ::= ","
SPLIT ::= "<:"
MIX ::= "+>"
MIX ::= ":>"
REC ::= "~"

ADD ::= "+"
SUB ::= "-"
MUL ::= "*"
DIV ::= "/"
MOD ::= "%"
FDELAY ::= "@"
DELAY1 ::= "'"

AND ::= "&"
OR ::= "|"
XOR ::= "xor"

LSH ::= "<<"
RSH ::= ">>"

LT ::= "<"
LE ::= "<="
GT ::= ">"
GE ::= ">="
EQ ::= "=="
NE ::= "!="

WIRE ::= "_"
CUT ::= "!"

ENDDEF ::= ";"
DEF ::= "="
LPAR ::= "("
RPAR ::= ")"
LBRAQ ::= "{"
RBRAQ ::= "}"
LCROC ::= "["
RCROC ::= "]"

LAMBDA ::= "\\"
DOT ::= "."
WITH ::= "with"
LETREC ::= "letrec"
WHERE ::= "where"

MEM ::= "mem"
PREFIX ::= "prefix"

INTCAST ::= "int"
FLOATCAST ::= "float"
NOTYPECAST ::= "any"

RDTBL ::= "rdtable"
RWTBL ::= "rwtable"

SELECT2 ::= "select2"
SELECT3 ::= "select3"

FFUNCTION ::= "ffunction"
FCONSTANT ::= "fconstant"
FVARIABLE ::= "fvariable"

BUTTON ::= "button"
CHECKBOX ::= "checkbox"
VSLIDER ::= "vslider"
HSLIDER ::= "hslider"
NENTRY ::= "nentry"
VGROUP ::= "vgroup"
HGROUP ::= "hgroup"
TGROUP ::= "tgroup"
VBARGRAPH ::= "vbargraph"
HBARGRAPH ::= "hbargraph"
SOUNDFILE ::= "soundfile"

ATTACH ::= "attach"

ACOS ::= "acos"
ASIN ::= "asin"
ATAN ::= "atan"
ATAN2 ::= "atan2"

COS ::= "cos"
SIN ::= "sin"
TAN ::= "tan"

EXP ::= "exp"
LOG ::= "log"
LOG10 ::= "log10"
POWOP ::= "^"
POWFUN ::= "pow"
SQRT ::= "sqrt"

ABS ::= "abs"
MIN ::= "min"
MAX ::= "max"

FMOD ::= "fmod"
REMAINDER ::= "remainder"

FLOOR ::= "floor"
CEIL ::= "ceil"
RINT ::= "rint"

ISEQ ::= "seq"
IPAR ::= "par"
ISUM ::= "sum"
IPROD ::= "prod"

INPUTS ::= "inputs"
OUTPUTS ::= "outputs"

IMPORT ::= "import"
COMPONENT ::= "component"
LIBRARY ::= "library"
ENVIRONMENT ::= "environment"

WAVEFORM ::= "waveform"
ROUTE ::= "route"
ENABLE ::= "enable"
CONTROL ::= "control"

DECLARE ::= "declare"

CASE ::= "case"
ARROW ::= "=>"

ASSERTBOUNDS ::= "assertbounds"
LOWEST ::= "lowest"
HIGHEST ::= "highest"

FLOATMODE ::= "singleprecision"
DOUBLEMODE ::= "doubleprecision"
QUADMODE ::= "quadprecision"
FIXEDPOINTMODE ::= "fixedpointprecision"

//"::"{NSID}       return IDENT;
//{NSID}           return IDENT;
mingodad commented 1 year ago

I've just added faustparser.y to https://mingodad.github.io/parsertl-playground/playground/ an Yacc/Lex compatible editor/tester (select Faust parser from Examples then click Parse to see a parser tree for the content in Input source editor).

Any feedback is welcome !