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

Open
mingodad opened this issue Sep 18, 2024 · 0 comments
Open

Grammar railroad diagram #56

mingodad opened this issue Sep 18, 2024 · 0 comments

Comments

@mingodad
Copy link

I've just added FrontC grammar to https://mingodad.github.io/parsertl-playground/playground/ an Yacc/Lex compatible online editor/tester that can also generate an EBNF understood by (IPV4) https://rr.red-dove.com/ui or (IPV6) https://www.bottlecaps.de/rr/ui to generate a nice navigable railroad diagram (see instructions bellow).

There is a good collection of grammars there (to see the FrontC select FrontC parser from Examples then click Parse to see a parser tree for the content in Input Source).

//
// EBNF to be viewd at
//    (IPV6) https://www.bottlecaps.de/rr/ui
//    (IPV4) https://rr.red-dove.com/ui
//
// Copy and paste this at one of the urls shown above in the 'Edit Grammar' tab
// then click the 'View Diagram' tab.
//

file::=
	  globals

globals::=
	  /*%empty*/
	| globals global

typedef::=
	  TYPEDEF typedef_type typedef_defs
	| gcc_attribute TYPEDEF typedef_type typedef_defs

global::=
	  global_type global_defs SEMICOLON
	| global_type global_proto body
	| global_type global_proto basic_asm opt_gcc_attributes SEMICOLON
	| global_type old_proto old_pardefs body
	| global_type SEMICOLON
	| typedef SEMICOLON

global_type::=
	  global_mod_list_zom global_qual
	| global_mod_list_zom comp_type global_mod_list_zom
	| global_mod_list_zom NAMED_TYPE global_mod_list_zom
	| global_mod_list_zom

global_mod_list_zom::=
	  /*%empty*/
	| global_mod global_mod_list_zom

global_mod::=
	  STATIC
	| CONST
	| VOLATILE
	| EXTERN
	| gcc_attribute

global_qual::=
	  qual_type
	| global_qual qual_type
	| global_qual global_mod

global_defs::=
	  global_def
	| global_defs COMMA global_def

global_def::=
	  global_dec opt_gcc_attributes
	| global_dec opt_gcc_attributes EQ init_expression

global_dec::=
	  IDENT
	| LPAREN global_dec RPAREN
	| STAR global_dec
	| STAR CONST global_dec
	| STAR VOLATILE global_dec
	| STAR RESTRICT global_dec
	| STAR gcc_attributes global_dec
	| global_dec LBRACKET comma_expression RBRACKET
	| global_dec LBRACKET RBRACKET
	| global_dec LPAREN parameters RPAREN
	| LPAREN global_dec RPAREN LPAREN parameters RPAREN
	| global_dec LPAREN old_parameters RPAREN
	| LPAREN global_dec RPAREN LPAREN old_parameters RPAREN

global_proto::=
	  global_dec opt_gcc_attributes

old_proto::=
	  global_dec opt_gcc_attributes

old_parameters::=
	  old_pardecs
	| old_pardecs ELLIPSIS

old_pardecs::=
	  IDENT
	| old_pardecs COMMA IDENT
	| old_pardecs COMMA NAMED_TYPE

old_pardefs::=
	  old_pardef
	| old_pardefs old_pardef

old_pardef::=
	  old_type old_defs SEMICOLON

old_type::=
	  old_mods_opt NAMED_TYPE old_mods_opt
	| old_mods_opt comp_type old_mods_opt
	| old_mods_opt old_qual

old_mods_opt::=
	  /*%empty*/
	| CONST
	| REGISTER

old_qual::=
	  qual_type
	| old_qual qual_type
	| old_qual CONST
	| old_qual REGISTER

old_defs::=
	  old_def
	| old_defs COMMA old_def

old_def::=
	  old_dec

old_dec::=
	  IDENT
	| STAR old_dec
	| STAR CONST old_dec
	| STAR VOLATILE old_dec
	| old_dec LBRACKET comma_expression RBRACKET
	| old_dec LBRACKET RBRACKET
	| old_dec LPAREN parameters RPAREN
	| LPAREN old_dec RPAREN LPAREN parameters RPAREN
	| LPAREN old_dec RPAREN

local::=
	  local_type local_defs SEMICOLON

local_type::=
	  local_mod_list_opt local_qual
	| local_mod_list_opt comp_type local_mod_list_opt
	| local_mod_list_opt NAMED_TYPE local_mod_list_opt

local_mod_list_opt::=
	  /*%empty*/
	| local_mod_list

local_mod_list::=
	  local_mod
	| local_mod_list local_mod

local_mod::=
	  STATIC
	| AUTO
	| CONST
	| VOLATILE
	| REGISTER
	| EXTERN
	| gcc_attribute

local_qual::=
	  qual_type
	| local_qual qual_type
	| local_qual local_mod

local_defs::=
	  local_def
	| local_defs COMMA local_def

local_def::=
	  local_dec opt_gcc_attributes
	| local_dec opt_gcc_attributes EQ init_expression

local_dec::=
	  IDENT
	| NAMED_TYPE
	| STAR local_dec
	| STAR RESTRICT local_dec
	| STAR CONST local_dec
	| STAR VOLATILE local_dec
	| STAR gcc_attributes local_dec
	| local_dec LBRACKET comma_expression RBRACKET
	| local_dec LBRACKET RBRACKET
	| local_dec LPAREN parameters RPAREN
	| LPAREN local_dec RPAREN LPAREN parameters RPAREN
	| LPAREN local_dec RPAREN

typedef_type::=
	  typedef_sub
	| CONST typedef_sub
	| VOLATILE typedef_sub

typedef_sub::=
	  NAMED_TYPE
	| comp_type
	| typedef_qual
	| IDENT
	| NAMED_TYPE CONST
	| NAMED_TYPE VOLATILE
	| comp_type CONST
	| comp_type VOLATILE
	| IDENT CONST
	| IDENT VOLATILE

typedef_qual::=
	  qual_type
	| typedef_qual qual_type
	| typedef_qual CONST
	| typedef_qual VOLATILE

typedef_defs::=
	  typedef_def
	| typedef_defs COMMA typedef_def

typedef_def::=
	  typedef_dec opt_gcc_attributes

typedef_dec::=
	  IDENT
	| NAMED_TYPE
	| STAR typedef_dec
	| STAR RESTRICT typedef_dec
	| STAR CONST typedef_dec
	| STAR VOLATILE typedef_dec
	| STAR gcc_attributes typedef_dec
	| typedef_dec LBRACKET comma_expression RBRACKET
	| typedef_dec LBRACKET RBRACKET
	| typedef_dec LPAREN parameters RPAREN
	| LPAREN typedef_dec RPAREN LPAREN parameters RPAREN
	| LPAREN typedef_dec RPAREN

field_list::=
	  /*%empty*/
	| field_list field

field::=
	  field_type field_defs opt_gcc_attributes SEMICOLON
	| field_mod_list_opt struct_type field_mod_list_opt field_defs SEMICOLON
	| field_mod_list_opt struct_type field_mod_list_opt SEMICOLON
	| field_mod_list_opt union_type field_mod_list_opt field_defs SEMICOLON
	| field_mod_list_opt union_type field_mod_list_opt SEMICOLON

field_type::=
	  field_mod_list_opt field_qual
	| field_mod_list_opt enum_type field_mod_list_opt
	| field_mod_list_opt NAMED_TYPE field_mod_list_opt

field_mod_list_opt::=
	  /*%empty*/
	| field_mod_list

field_mod_list::=
	  field_mod
	| field_mod_list field_mod

field_mod::=
	  CONST
	| VOLATILE
	| gcc_attribute

field_qual::=
	  qual_type
	| field_qual qual_type
	| field_qual field_mod

field_defs::=
	  field_def
	| field_defs COMMA field_def

field_def::=
	  field_dec

field_dec::=
	  IDENT
	| NAMED_TYPE
	| STAR field_dec
	| STAR RESTRICT field_dec
	| STAR CONST field_dec
	| STAR VOLATILE field_dec
	| STAR gcc_attributes field_dec
	| field_dec LBRACKET comma_expression RBRACKET
	| field_dec LBRACKET RBRACKET
	| field_dec LPAREN parameters RPAREN
	| LPAREN field_dec RPAREN LPAREN parameters RPAREN
	| LPAREN field_dec RPAREN
	| option_IDENT_ COLON expression

parameters::=
	  /*%empty*/
	| param_list
	| param_list COMMA ELLIPSIS

param_list::=
	  param_list COMMA param
	| param

param::=
	  param_type param_def

param_type::=
	  param_mods_opt NAMED_TYPE param_mods_opt
	| param_mods_opt comp_type param_mods_opt
	| param_mods_opt param_qual

param_mods_opt::=
	  /*%empty*/
	| param_mods

param_mods::=
	  param_mod
	| param_mods param_mod

param_mod::=
	  CONST
	| REGISTER
	| VOLATILE
	| gcc_attribute

param_qual::=
	  qual_type
	| param_qual qual_type
	| param_qual CONST
	| param_qual REGISTER
	| param_qual VOLATILE
	| param_qual gcc_attribute

param_def::=
	  param_dec

param_dec::=
	  /*%empty*/
	| IDENT
	| NAMED_TYPE
	| STAR param_dec
	| STAR RESTRICT param_dec
	| STAR CONST param_dec
	| STAR VOLATILE param_dec
	| STAR gcc_attributes param_dec
	| param_dec LBRACKET global_mod_list_zom comma_expression RBRACKET
	| param_dec LBRACKET global_mod_list_zom RBRACKET
	| LPAREN param_dec RPAREN LPAREN parameters RPAREN
	| LPAREN param_dec RPAREN

only_type::=
	  only_type_type only_def

only_type_type::=
	  only_mod_list_opt only_qual
	| only_mod_list_opt comp_type only_mod_list_opt
	| only_mod_list_opt NAMED_TYPE only_mod_list_opt

only_mod_list_opt::=
	  /*%empty*/
	| only_mod_list

only_qual::=
	  qual_type
	| only_qual qual_type
	| only_qual only_mod

only_mod_list::=
	  only_mod
	| only_mod_list only_mod

only_mod::=
	  CONST
	| VOLATILE
	| gcc_attribute

only_def::=
	  only_dec

only_dec::=
	  /*%empty*/
	| STAR only_dec
	| STAR RESTRICT only_dec
	| STAR CONST only_dec
	| STAR VOLATILE only_dec
	| STAR gcc_attributes only_dec
	| only_dec LBRACKET comma_expression RBRACKET
	| only_dec LBRACKET RBRACKET
	| LPAREN only_dec RPAREN LPAREN parameters RPAREN
	| LPAREN only_dec RPAREN

qual_type::=
	  VOID
	| BOOL
	| CHAR
	| INT
	| FLOAT
	| DOUBLE
	| BUILTIN_TYPE
	| COMPLEX
	| LONG
	| SHORT
	| SIGNED
	| UNSIGNED

comp_type::=
	  struct_type
	| union_type
	| enum_type

struct_type::=
	  STRUCT type_name
	| STRUCT LBRACE field_list RBRACE
	| STRUCT type_name LBRACE field_list RBRACE

union_type::=
	  UNION type_name
	| UNION LBRACE field_list RBRACE
	| UNION type_name LBRACE field_list RBRACE

enum_type::=
	  ENUM type_name
	| ENUM LBRACE enum_list RBRACE
	| ENUM LBRACE enum_list COMMA RBRACE
	| ENUM type_name LBRACE enum_list RBRACE

type_name::=
	  IDENT
	| NAMED_TYPE

enum_list::=
	  enum_name
	| enum_list COMMA enum_name

enum_name::=
	  IDENT
	| IDENT EQ expression

init_expression::=
	  LBRACE compound_comma_expression RBRACE
	| expression

compound_expression::=
	  LBRACE compound_comma_expression RBRACE
	| expression
	| DOT type_name EQ expression

compound_comma_expression::=
	  compound_expression
	| compound_comma_expression COMMA compound_expression
	| compound_comma_expression COMMA

opt_expression::=
	  /*%empty*/
	| comma_expression

comma_expression::=
	  expression
	| comma_expression COMMA expression

expression::=
	  LPAREN EXTENSION expression RPAREN
	| constant
	| IDENT
	| SIZEOF expression
	| SIZEOF LPAREN only_type RPAREN
	| PLUS expression
	| MINUS expression
	| STAR expression
	| AND expression
	| EXCLAM expression
	| TILDE expression
	| PLUS_PLUS expression
	| expression PLUS_PLUS
	| MINUS_MINUS expression
	| expression MINUS_MINUS
	| expression ARROW IDENT
	| expression ARROW NAMED_TYPE
	| expression DOT IDENT
	| expression DOT NAMED_TYPE
	| LPAREN body RPAREN
	| LPAREN comma_expression RPAREN
	| LPAREN only_type RPAREN expression
	| expression LPAREN opt_expression RPAREN
	| expression LBRACKET comma_expression RBRACKET
	| expression QUEST expression COLON expression
	| expression PLUS expression
	| expression MINUS expression
	| expression STAR expression
	| expression SLASH expression
	| expression PERCENT expression
	| expression AND_AND expression
	| expression PIPE_PIPE expression
	| expression AND expression
	| expression PIPE expression
	| expression CIRC expression
	| expression EQ_EQ expression
	| expression EXCLAM_EQ expression
	| expression INF expression
	| expression SUP expression
	| expression INF_EQ expression
	| expression SUP_EQ expression
	| expression INF_INF expression
	| expression SUP_SUP expression
	| expression EQ expression
	| expression PLUS_EQ expression
	| expression MINUS_EQ expression
	| expression STAR_EQ expression
	| expression SLASH_EQ expression
	| expression PERCENT_EQ expression
	| expression AND_EQ expression
	| expression PIPE_EQ expression
	| expression CIRC_EQ expression
	| expression INF_INF_EQ expression
	| expression SUP_SUP_EQ expression

constant::=
	  CST_INT
	| CST_FLOAT
	| CST_CHAR
	| string_list

string_list::=
	  CST_STRING
	| string_list CST_STRING

body_begin::=
	  LBRACE

body_middle::=
	  opt_locals opt_stats

body::=
	  body_begin body_middle RBRACE

opt_locals::=
	  /*%empty*/
	| locals

locals::=
	  local
	| locals local

opt_stats::=
	  /*%empty*/
	| stats

stats::=
	  statement
	| stats statement

statement::=
	  SEMICOLON
	| comma_expression SEMICOLON
	| body
	| IF LPAREN comma_expression RPAREN statement
	| IF LPAREN comma_expression RPAREN statement ELSE statement
	| SWITCH LPAREN comma_expression RPAREN statement
	| WHILE LPAREN comma_expression RPAREN statement
	| DO statement WHILE LPAREN comma_expression RPAREN SEMICOLON
	| FOR LPAREN opt_expression SEMICOLON opt_expression SEMICOLON opt_expression RPAREN statement
	| IDENT COLON statement
	| CASE expression COLON statement
	| DEFAULT COLON statement
	| RETURN SEMICOLON
	| RETURN expression SEMICOLON
	| BREAK SEMICOLON
	| CONTINUE SEMICOLON
	| GOTO IDENT SEMICOLON
	| ASM LPAREN CST_STRING RPAREN SEMICOLON
	| ASM LPAREN CST_STRING gnu_asm_io gnu_asm_io opt_gnu_asm_mods RPAREN SEMICOLON

basic_asm::=
	  ASM option_VOLATILE_ opt_gcc_attributes LPAREN string_list RPAREN

gnu_asm_io::=
	  COLON gnu_asm_args

gnu_asm_args::=
	  gnu_asm_arg
	| gnu_asm_args COMMA gnu_asm_arg

gnu_asm_arg::=
	  CST_STRING LPAREN expression RPAREN
	| LBRACKET IDENT RBRACKET CST_STRING LPAREN expression RPAREN

opt_gnu_asm_mods::=
	  /*%empty*/
	| COLON gnu_asm_mods

gnu_asm_mods::=
	  CST_STRING
	| gnu_asm_mods COMMA CST_STRING

opt_gcc_attributes::=
	  /*%empty*/
	| gcc_attributes

gcc_attributes::=
	  gcc_attribute
	| gcc_attributes gcc_attribute

gcc_attribute::=
	  ATTRIBUTE LPAREN LPAREN opt_gnu_args RPAREN RPAREN
	| EXTENSION
	| INLINE

opt_gnu_args::=
	  /*%empty*/
	| gnu_args

gnu_args::=
	  gnu_arg
	| gnu_args COMMA gnu_arg

gnu_arg::=
	  gnu_id
	| local_type
	| constant
	| gnu_id LPAREN opt_gnu_args RPAREN

gnu_id::=
	  IDENT
	| GNU_ATTRS

option_IDENT_::=
	  /*%empty*/
	| IDENT

option_VOLATILE_::=
	  /*%empty*/
	| VOLATILE


//Tokens

AUTO ::= "auto"
CONST ::= "const"|"__const"
STATIC ::= "static"
EXTERN ::= "extern"
LONG ::= "long"
COMPLEX ::= "_Complex"
BUILTIN_TYPE ::= "__float128"
BUILTIN_TYPE ::= "__float80"
BUILTIN_TYPE ::= "__ibm128"
BUILTIN_TYPE ::= "_Float16"
BUILTIN_TYPE ::= "_Float32"
BUILTIN_TYPE ::= "_Float32x"
BUILTIN_TYPE ::= "_Float64"
BUILTIN_TYPE ::= "_Float64x"
BUILTIN_TYPE ::= "_Float80"
BUILTIN_TYPE ::= "_Float128"
BUILTIN_TYPE ::= "_Float128x"
BUILTIN_TYPE ::= "_Ibm128"
SHORT ::= "short"
REGISTER ::= "register"
SIGNED ::= "signed"
UNSIGNED ::= "unsigned"
VOLATILE ::= "volatile"
INLINE ::= "inline"
RESTRICT ::= "__restrict"
RESTRICT ::= "restrict"
CHAR ::= "char"
BOOL ::= "_Bool"
INT ::= "int"
FLOAT ::= "float"
DOUBLE ::= "double"
VOID ::= "void"
ENUM ::= "enum"
STRUCT ::= "struct"
TYPEDEF ::= "typedef"
UNION ::= "union"
BREAK ::= "break"
CONTINUE ::= "continue"
GOTO ::= "goto"
RETURN ::= "return"
SWITCH ::= "switch"
CASE ::= "case"
DEFAULT ::= "default"
WHILE ::= "while"
DO ::= "do"
FOR ::= "for"
IF ::= "if"
ELSE ::= "else"
ASM ::= "asm"|"__asm__"
SIZEOF ::= "sizeof"

//Specific ::= /*** ***/ ::= GNU
ATTRIBUTE ::= "__attribute__"
EXTENSION ::= "__extension__"
INLINE ::= "__inline"
//GNU_ATTRS ::= GNU_ATTRS

ELLIPSIS ::= "..."
PLUS_EQ ::= "+="
MINUS_EQ ::= "-="
STAR_EQ ::= "*="
SLASH_EQ ::= "/="
PERCENT_EQ ::= "%="
PIPE_EQ ::= "|="
AND_EQ ::= "&="
CIRC_EQ ::= "^="
INF_INF_EQ ::= "<<="
SUP_SUP_EQ ::= ">>="
INF_INF ::= "<<"
SUP_SUP ::= ">>"
EQ_EQ ::= "=="
EXCLAM_EQ ::= "!="
INF_EQ ::= "<="
SUP_EQ ::= ">="
EQ ::= "="
INF ::= "<"
SUP ::= ">"
PLUS_PLUS ::= "++"
MINUS_MINUS ::= "--"
ARROW ::= "->"
PLUS ::= "+"
MINUS ::= "-"
STAR ::= "*"
SLASH ::= "/"
PERCENT ::= "%"
EXCLAM ::= "!"
AND_AND ::= "&&"
PIPE_PIPE ::= "||"
AND ::= "&"
PIPE ::= "|"
CIRC ::= "^"
QUEST ::= "?"
COLON ::= ":"
TILDE ::= "~"

LBRACE ::= "{"
RBRACE ::= "}"
LBRACKET ::= "["
RBRACKET ::= "]"
LPAREN ::= "("
RPAREN ::= ")"
SEMICOLON ::= ";"
COMMA ::= ","
DOT ::= "."
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