intel / intel/confidential-computing.sgx.sdk

Grammar railroad diagram

Open
#92 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
C++
Stars
2
Forks
3
PR merge metrics
No merged PRs in 30d

Description

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 `sdk/edger8r/linux/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/intel/linux-sgx/master/sdk/edger8r/linux/Parser.mly
*/

start_parsing ::= enclave_def TSemicolon EOFenclave_def ::= Tenclave TLBrace expressions TRBrace
expressions ::= /* empty */ | expressions include_declaration | expressions import_declaration TSemicolon | expressions composite_defs TSemicolon | expressions enclave_functions
allow_list ::= /* empty */ | Tallow TLParen TRParen | Tallow TLParen func_list TRParen
untrusted_func_def ::= untrusted_prefixes func_def allow_list untrusted_postfixes
untrusted_postfixes ::= /* empty */ | Tpropagate_errno switchless_annotation | Tswitchless propagate_errno
untrusted_prefixes ::= /* empty */ | attr_block
propagate_errno ::= /* empty */ | Tpropagate_errno
parameter_def ::= param_type declarator
parameter_defs ::= parameter_def | parameter_defs TComma parameter_def
parameter_list ::= TLParen TRParen | TLParen Tvoid TRParen | TLParen parameter_defs TRParen
func_def ::= all_type Tidentifier parameter_list | all_type array_size Tidentifier parameter_list
untrusted_functions ::= /* empty */ | untrusted_functions untrusted_func_def TSemicolon
trusted_functions ::= /* empty */ | trusted_functions access_modifier func_def switchless_annotation TSemicolon
switchless_annotation ::= /* empty */ | Tswitchless
access_modifier ::= /* empty */ | Tpublic
untrusted_block ::= untrusted_functions | include_declarations untrusted_functions
trusted_block ::= trusted_functions | include_declarations trusted_functions
enclave_functions ::= Ttrusted TLBrace trusted_block TRBrace TSemicolon | Tuntrusted TLBrace untrusted_block TRBrace TSemicolon
include_declarations ::= include_declaration | include_declarations include_declaration
include_declaration ::= Tinclude Tstring
import_declaration ::= Tfrom module_path Timport func_list | Tfrom module_path Timport TPtr
module_path ::= Tstring
func_list ::= Tidentifier | func_list TComma Tidentifier
union_member_def ::= all_type declarator
struct_member_def ::= smember_type declarator
union_member_list ::= union_member_def TSemicolon | union_member_list union_member_def TSemicolon
struct_member_list ::= struct_member_def TSemicolon | struct_member_list struct_member_def TSemicolon
composite_defs ::= struct_definition | union_definition | enum_definition
enum_ele ::= Tidentifier | Tidentifier TEqual Tidentifier | Tidentifier TEqual Tnumber
enum_eles ::= enum_ele | enum_eles TComma enum_ele
enum_body ::= /* empty */ | enum_eles
enum_definition ::= Tenum TLBrace enum_body TRBrace | enum_specifier TLBrace enum_body TRBrace
union_definition ::= union_specifier TLBrace union_member_list TRBrace
struct_definition ::= struct_specifier TLBrace struct_member_list TRBrace
enum_specifier ::= Tenum Tidentifier
union_specifier ::= Tunion Tidentifier
struct_specifier ::= Tstruct Tidentifier
key_val_pair ::= Tidentifier TEqual Tidentifier | Tidentifier TEqual Tnumber | Tidentifier
key_val_pairs ::= key_val_pair | key_val_pairs TComma key_val_pair
attr_block ::= TLBrack TRBrack | TLBrack key_val_pairs TRBrack
smember_type ::= attr_block all_type | all_type
param_type ::= attr_block all_type | all_type | attr_block Tconst type_spec pointer | Tconst type_spec pointer
declarator ::= Tidentifier | Tidentifier array_size
all_type ::= type_spec | type_spec pointer
array_size ::= fixed_size_array | empty_dimension | empty_dimension fixed_size_array
fixed_size_array ::= fixed_dimension | fixed_size_array fixed_dimension
fixed_dimension ::= TLBrack Tnumber TRBrack
empty_dimension ::= TLBrack TRBrack
pointer ::= TPtr | pointer TPtr
type_spec ::= char_type | int_type | Tfloat | Tdouble | Tlong Tdouble | Tint8 | Tint16 | Tint32 | Tint64 | Tuint8 | Tuint16 | Tuint32 | Tuint64 | Tsizet | Twchar | Tvoid | struct_specifier | union_specifier | enum_specifier | Tidentifier
int_type ::= shortness Tint | Tunsigned shortness Tint | Tunsigned shortness | longlong | ex_shortness
shortness ::= /* empty */ | ex_shortness
longlong ::= Tlong Tlong | Tunsigned Tlong Tlong
ex_shortness ::= Tshort | Tlong
char_type ::= Tchar | Tunsigned Tchar

// Tokens

/* data types */
Tchar ::= "char"
Tshort ::= "short"
Tunsigned ::= "unsigned"
Tint ::= "int"
Tfloat ::= "float"
Tdouble ::= "double"

Tint8 ::= "int8_t"
Tint16 ::= "int16_t"
Tint32 ::= "int32_t"
Tint64 ::= "int64_t"

Tuint8 ::= "uint8_t"
Tuint16 ::= "uint16_t"
Tuint32 ::= "uint32_t"
Tuint64 ::= "uint64_t"

Tsizet ::= "size_t"
Twchar ::= "wchar_t"
Tlong ::= "long"
Tvoid ::= "void"

Tstruct ::= "struct"
Tunion ::= "union"
Tenum ::= "enum"

/* specifier */
Tenclave ::= "enclave"
Ttrusted ::= "trusted"
Tuntrusted ::= "untrusted"
Tfrom ::= "from"
Timport ::= "import"
Tallow ::= "allow"
Tpublic ::= "public"
Tswitchless ::= "transition_using_threads"
Tinclude ::= "include"
Tpropagate_errno ::= "propagate_errno"

/* Type qualifier */
Tconst ::= "const"

/* symbols */
TLBrace ::= '{'
TRBrace ::= '}'
TLParen ::= '('
TRParen ::= ')'
TLBrack ::= '['
TRBrack ::= ']'
TPtr ::= '*'
TDot ::= '.'
TComma ::= ','
TSemicolon ::= ';'
TEqual ::= '='
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.