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 #57

Open
mingodad opened this issue Jun 29, 2021 · 0 comments
Open

Grammar railroad diagram #57

mingodad opened this issue Jun 29, 2021 · 0 comments

Comments

@mingodad
Copy link

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/3d/ocaml/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/project-everest/everparse/master/src/3d/ocaml/parser.mly
*/

option_of ::=  /* empty */ | X
right_flexible_list ::=  /* empty */ | X | X SEP right_flexible_list
right_flexible_nonempty_list ::=  X | X SEP right_flexible_list
constant ::=  INT | XINT | BOOL
rel_op ::=  DOUBLEEQ | NEQ | LEQ | LESS_THAN | GEQ | GREATER_THAN
else_opt ::=  /* empty */ | ELSE LBRACE expr RBRACE
atomic_expr ::=  qident | THIS | constant
atomic_or_paren_expr ::=  atomic_expr | LPAREN expr RPAREN
castable_expr ::=  /* empty */ | atomic_expr | LPAREN expr RPAREN
expr_no_range ::=  atomic_expr | LPAREN expr RPAREN castable_expr | expr rel_op expr | expr AND expr | expr OR expr | expr MINUS expr | expr PLUS expr | expr STAR expr | expr DIV expr | expr REM expr | expr BITWISE_AND expr | expr BITWISE_XOR expr | expr BITWISE_OR expr | BITWISE_NOT expr | expr SHIFT_RIGHT expr | expr SHIFT_LEFT expr | NOT expr | SIZEOF LPAREN expr RPAREN | atomic_or_paren_expr QUESTION atomic_or_paren_expr COLON atomic_or_paren_expr | IF expr LBRACE expr RBRACE else_opt | IDENT LPAREN arguments RPAREN
expr ::=  expr_no_range
arguments ::=  right_flexible_nonempty_list
qident ::=  IDENT | IDENT DOT IDENT
typ_no_range ::=  qident | qident LPAREN arguments RPAREN
typ ::=  typ_no_range
maybe_pointer_typ ::=  typ | pointer_typ
pointer_typ ::=  maybe_pointer_typ STAR
refinement ::=  LBRACE expr RBRACE
array_size ::=  LBRACK expr RBRACK | LBRACK_BYTESIZE expr RBRACK | LBRACK_LEQ expr RBRACK | LBRACK_BYTESIZE_AT_MOST expr RBRACK | LBRACK_EQ expr RBRACK | LBRACK_SINGLE_ELEMENT_BYTESIZE expr RBRACK
array_annot ::=  /* empty */ | array_size | LBRACK_STRING RBRACK | LBRACK_STRING_AT_MOST expr RBRACK
bitwidth ::=  COLON INT
field_action ::=  LBRACE_ONSUCCESS action RBRACE
struct_field ::=  typ IDENT option_of array_annot option_of option_of
field ::=  struct_field
immutable_parameter ::=  typ IDENT
mutable_parameter ::=  MUTABLE pointer_typ IDENT
parameter ::=  immutable_parameter | mutable_parameter
parameters ::=  /* empty */ | LPAREN right_flexible_nonempty_list RPAREN
case_pattern ::=  qident | constant
case ::=  CASE case_pattern COLON field | DEFAULT COLON field
cases ::=  right_flexible_nonempty_list
attribute ::=  ENTRYPOINT | ALIGNED
attributes ::=  /* empty */ | attribute attributes
where_opt ::=  /* empty */ | WHERE expr | REQUIRES expr
atomic_action ::=  RETURN expr SEMICOLON | ABORT SEMICOLON | FIELD_POS SEMICOLON | FIELD_PTR SEMICOLON | STAR IDENT SEMICOLON | STAR IDENT EQ expr SEMICOLON | IDENT LPAREN arguments RPAREN SEMICOLON
action_else ::=  ELSE LBRACE action RBRACE
action_no_range ::=  atomic_action | atomic_action action | IF expr LBRACE action RBRACE option_of | VAR IDENT EQ atomic_action action
action ::=  action_no_range
enum_case ::=  IDENT | IDENT EQ INT | IDENT EQ IDENT
exported ::=  /* empty */ | EXPORT
maybe_semi ::=  /* empty */ | SEMICOLON
typedef_pointer_name_opt ::=  /* empty */ | COMMA STAR IDENT
decl_no_range ::=  MODULE IDENT EQ IDENT | DEFINE IDENT constant | IDENT ENUM IDENT LBRACE right_flexible_nonempty_list RBRACE maybe_semi | attributes TYPEDEF typ IDENT SEMICOLON | attributes TYPEDEF STRUCT IDENT parameters where_opt LBRACE right_flexible_nonempty_list RBRACE IDENT typedef_pointer_name_opt SEMICOLON | attributes CASETYPE IDENT parameters LBRACE SWITCH LPAREN IDENT RPAREN LBRACE cases RBRACE RBRACE IDENT typedef_pointer_name_opt SEMICOLON
block_comment_opt ::=  /* empty */ | BLOCK_COMMENT
decl ::=  block_comment_opt exported decl_no_range
expr_top ::=  expr EOF
type_map ::=  IDENT | IDENT AS IDENT
type_refinement ::=  REFINING right_flexible_nonempty_list LBRACE right_flexible_nonempty_list RBRACE
prog ::=  decl option_of EOF | decl prog

// Tokens

WHERE ::= "where"
REQUIRES ::= "requires"
SIZEOF ::= "sizeof"
ENUM ::= "enum"
TYPEDEF ::= "typedef"
STRUCT ::= "struct"
CASETYPE ::= "casetype"
SWITCH ::= "switch"
CASE ::= "case"
DEFAULT ::= "default"
THIS ::= "this"
ENTRYPOINT ::= "entrypoint"
ALIGNED ::= "aligned"
IF ::= "if"
ELSE ::= "else"
MUTABLE ::= "mutable"
FIELD_POS ::= "field_pos"
FIELD_PTR ::= "field_ptr"
VAR ::= "var"
ABORT ::= "abort"
RETURN ::= "return"
REFINING ::= "refining"
AS ::= "as"
MODULE ::= "module"
EXPOR ::= "export"

DEFINE ::= "#define"
LPAREN ::= "("
RPAREN ::= ")"
SHIFT_LEFT ::= "<<"
SHIFT_RIGHT ::= ">>"
GEQ ::= ">="
LEQ ::= "<="
GREATER_THAN ::= ">"
LESS_THAN ::= "<"
DOUBLEEQ ::= "=="
EQ ::= "="
NEQ ::= "!="
NOT ::= "!"
AND ::= "&&"
BITWISE_AND ::= "&"
OR ::= "||"
BITWISE_OR ::= "|"
BITWISE_XOR ::= "^"
BITWISE_NOT ::= "~"
DOT ::= "."
COMMA ::= ","
SEMICOLON ::= ";"
COLON ::= ":"
QUESTION ::= "?"
LBRACE_ONSUCCESS ::= "{:on-success"
LBRACE ::= "{"
RBRACE ::= "}"
LBRACK_BYTESIZE ::= "[:byte-size"
LBRACK_BYTESIZE_AT_MOST ::= "[:byte-size-single-element-array-at-most"
LBRACK_SINGLE_ELEMENT_BYTESIZE ::= "[:byte-size-single-element-array"
LBRACK_STRING ::= "[:zeroterm"
LBRACK_STRING_AT_MOST ::= "[:zeroterm-byte-size-at-most"
LBRACK ::= "["
RBRACK ::= "]"
LBRACK_EQ ::= "[="
LBRACK_LEQ ::= "[<="
STAR ::= "*"
DIV ::= "/"
REM ::= "%"
PLUS ::= "+"
MINUS ::= "-"
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