-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Grammar railroad diagram #1
Comments
The current grammar has no shift-reduce or reduce-reduce warnings. I'm
open to suggestions on how to reorder the grammar for better graphical
representation provided that would still hold and all tests pass.
…On Tue, Jun 29, 2021 at 4:10 AM Domingo Alvarez Duarte < ***@***.***> wrote:
I've done a experimental tool to convert bison grammars to a kind of EBNF
understood by https://www.bottlecaps.de/rr/ui to generate railroad
diagrams see bellow the converted src/lib/parser.mly and with some hand
made changes to allow view it at https://www.bottlecaps.de/rr/ui the
order of the rules could be changed to a better view of the railroad
diagrams. Copy and paste the EBNF bellow on
https://www.bottlecaps.de/rr/ui tab Edit Grammar then switch to the tab
View Diagram.
/*
From https://raw.githubusercontent.com/drjdn/ocaml_lua_parser/master/src/lib/parser.mly
*/
prog ::= chunk EOF
chunk ::= statlist retstat OSC | statlist
statlist ::= OSC | statlist stat OSC
block ::= chunk
stat ::= varlist ASSIGN explist | functioncall | label | GOTO ident | DO block END | WHILE exp DO block END | REPEAT block UNTIL exp | IF exp THEN block END | IF exp THEN block ELSE block END | IF exp THEN block elseifps END | IF exp THEN block elseifps ELSE block END | FOR ident ASSIGN exp COMMA exp DO block END | FOR ident ASSIGN exp COMMA exp COMMA exp DO block END | FOR namelist IN explist DO block END | FUNCTION funcname funcbody | LOCAL FUNCTION ident funcbody | LOCAL namelist | LOCAL namelist ASSIGN explist
elseifp ::= ELSEIF exp THEN block
elseifps ::= elseifp | elseifps elseifp
retstat ::= RETURN | RETURN explist | BREAK
label ::= DCOLON ident DCOLON
funcname ::= fname | fname COLON ident
varlist ::= var | varlist COMMA var
var ::= ident | bracket key | functioncall key | var key
key ::= LB exp RB | DOT ident
fname ::= ident | fname DOT ident
namelist ::= ident | namelist COMMA ident
explist ::= exp | explist COMMA exp
exp ::= primary | var | functioncall | exp OR exp | exp AND exp | exp LT exp | exp GT exp | exp LE exp | exp GE exp | exp NE exp | exp EQ exp | exp CAT exp | exp PLUS exp | exp MINUS exp | exp MULT exp | exp DIV exp | exp MOD exp | exp CARAT exp | NOT exp | HASH exp | MINUS exp
primary ::= BOOL | NUM_CONST | STR_CONST | ELLIPSIS | functiondef | tableconstructor | bracket
bracket ::= LPAR exp RPAR
functioncall ::= bracket args | bracket COLON ident args | var args | var COLON ident args | functioncall args | functioncall COLON ident args
args ::= LPAR RPAR | LPAR explist RPAR | tableconstructor | STR_CONST
functiondef ::= FUNCTION funcbody
funcbody ::= LPAR RPAR block END | LPAR parlist RPAR block END
parlist ::= namelist | namelist COMMA ELLIPSIS | ELLIPSIS
tableconstructor ::= LCB RCB | LCB fieldlist RCB
fieldlist ::= fields | fields fieldsep
fields ::= field | fields fieldsep field
field ::= LB exp RB ASSIGN exp | ident ASSIGN exp | exp
fieldsep ::= COMMA | SEMI
ident ::= IDENT
OSC ::= /* empty */ | SEMI
// Tokens
PLUS ::= "+"
MINUS ::= "-"
MULT ::= "*"
DIV ::= "/"
MOD ::= "%"
CARAT ::= "^"
GT ::= ">"
LT ::= "<"
GE ::= ">="
LE ::= "<="
EQ ::= "=="
NE ::= "~="
ASSIGN ::= "="
DOT ::= "."
CAT ::= ".."
ELLIPSIS ::= "..."
COLON ::= ":"
DCOLON ::= "::"
SEMI ::= ";"
COMMA ::= ","
HASH ::= "#"
LCB ::= "{"
RCB ::= "}"
LPAR ::= "("
RPAR ::= ")"
LB ::= "["
RB ::= "]"
AND ::= "and"
BREAK ::= "break"
DO ::= "do"
ELSE ::= "else"
ELSEIF ::= "elseif"
END ::= "end"
FOR ::= "for"
FUNCTION ::= "function"
GOTO ::= "goto"
IF ::= "if"
IN ::= "in"
LOCAL ::= "local"
NOT ::= "not"
OR ::= "or"
REPEAT ::= "repeat"
RETURN ::= "return"
THEN ::= "then"
UNTIL ::= "until"
WHILE ::= "while"
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJWETVVNHCQTF6QRD3HKDDTVF5YFANCNFSM47PR5P5Q>
.
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've done a experimental tool to convert bison grammars to a kind of EBNF understood by https://www.bottlecaps.de/rr/ui to generate railroad diagrams see bellow the converted
src/lib/parser.mly
and with some hand made changes to allow view it at https://www.bottlecaps.de/rr/ui the order of the rules could be changed to a better view of the railroad diagrams. Copy and paste the EBNF bellow on https://www.bottlecaps.de/rr/ui tab Edit Grammar then switch to the tab View Diagram.The text was updated successfully, but these errors were encountered: