Skip to content
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 #7

Open
mingodad opened this issue Feb 7, 2023 · 0 comments
Open

Grammar railroad diagram #7

mingodad opened this issue Feb 7, 2023 · 0 comments

Comments

@mingodad
Copy link

mingodad commented Feb 7, 2023

Using a extended lemon to generate railroad diagrams (https://en.wikipedia.org/wiki/Syntax_diagram) here https://github.com/mingodad/lalr-parser-test and manually adding the tokens we can get an EBNF compatible with https://www.bottlecaps.de/rr/ui to get a nice navigable railroad diagram.

Copy and paste the EBNF shown bellow on https://www.bottlecaps.de/rr/ui in the tab "Edit Grammar" then switch to the tab "View Diagram".

chunk ::= block

semi ::= SEMICOL
semi ::= /*empty*/

block ::= scope statlist
block ::= scope statlist laststat semi

ublock ::= block UNTIL exp

scope ::= /*empty*/
scope ::= scope statlist binding semi

statlist ::= /*empty*/
statlist ::= statlist stat semi

stat ::= DO block END
stat ::= WHILE exp DO block END
stat ::= repetition DO block END
stat ::= REPEAT ublock
stat ::= IF conds END
stat ::= FUNCTION funcname params block END
stat ::= setlist SET explist1
stat ::= functioncall

repetition ::= FOR NAME SET explist23
repetition ::= FOR namelist IN explist1

conds ::= condlist
conds ::= condlist ELSE block

condlist ::= cond
condlist ::= condlist ELSEIF cond

cond ::= exp THEN block

laststat ::= BREAK
laststat ::= RETURN
laststat ::= RETURN explist1

binding ::= LOCAL namelist
binding ::= LOCAL namelist SET explist1
binding ::= LOCAL FUNCTION NAME params block END

funcname ::= dottedname
funcname ::= dottedname COLON NAME

dottedname ::= NAME
dottedname ::= dottedname DOT NAME

namelist ::= NAME
namelist ::= namelist COMMA NAME

explist1 ::= exp
explist1 ::= explist1 COMMA exp

explist23 ::= exp COMMA exp
explist23 ::= exp COMMA exp COMMA exp

exp ::= NIL
exp ::= TRUE|FALSE
exp ::= DOTS
exp ::= NUMBER
exp ::= STRING
exp ::= function
exp ::= prefixexp
exp ::= tableconstructor
exp ::= HASH exp
exp ::= NOT|MINUS exp
exp ::= exp OR|AND exp
exp ::= exp L|LE|G|GE|EQ|NE exp
exp ::= exp CONCAT exp
exp ::= exp PLUS|MINUS|TIMES|DIVIDE|MOD|POW exp

setlist ::= var
setlist ::= setlist COMMA var

var ::= NAME
var ::= prefixexp SLPAREN exp SRPAREN
var ::= prefixexp DOT NAME

prefixexp ::= var
prefixexp ::= functioncall
prefixexp ::= OPEN exp RPAREN

functioncall ::= prefixexp args
functioncall ::= prefixexp COLON NAME args

args ::= LPAREN RPAREN
args ::= LPAREN explist1 RPAREN
args ::= tableconstructor
args ::= STRING

function ::= FUNCTION params block END

params ::= LPAREN parlist LPAREN

parlist ::= /*empty*/
parlist ::= namelist
parlist ::= DOTS
parlist ::= namelist COMMA DOTS

tableconstructor ::= LBRACE RBRACE
tableconstructor ::= LBRACE fieldlist RBRACE
tableconstructor ::= LBRACE fieldlist COMMA|SEMICOL RBRACE

fieldlist ::= field
fieldlist ::= fieldlist COMMA|SEMICOL field

field ::= exp
field ::= NAME SET exp
field ::= SLPAREN exp SRPAREN SET exp

//Tokens

//{TK_\([^,]+\), \("[^"]+"\)},

AND ::= "and"
BREAK ::= "break"
DO ::= "do"
ELSEIF ::= "elseif"
ELSE ::= "else"
END ::= "end"
FALSE ::= "false"
FOR ::= "for"
FUNCTION ::= "function"
IF ::= "if"
IN ::= "in"
LOCAL ::= "local"
NIL ::= "nil"
NOT ::= "not"
OR ::= "or"
REPEAT ::= "repeat"
RETURN ::= "return"
THEN ::= "then"
TRUE ::= "true"
UNTIL ::= "until"
WHILE ::= "while"
CONCAT ::= ".."
DOTS ::= "..."
EQ ::= "=="
GE ::= ">="
LE ::= "<="
NE ::= "~="

//case \('[^']+'\):\s+return TK_\([^;]+\);
PLUS ::= '+'
MINUS ::= '-'
TIMES ::= '*'
DIVIDE ::= '/'
LPAREN ::= '('
RPAREN ::= ')'
SEMICOL ::= ';'
COLON ::= ':'
COMMA ::= ','
SRPAREN ::= ']'
LBRACE ::= '{'
RBRACE ::= '}'
HASH ::= '#'
MOD ::= '%'
POW ::= '^'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant