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

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

Grammar railroad diagram #33

mingodad opened this issue Feb 26, 2023 · 0 comments

Comments

@mingodad
Copy link

Using some online tools like https://www.bottlecaps.de/rr/ui and https://www.bottlecaps.de/convert/ we can have a nice navigable railroad diagram.

Copy and paste the EBNF shown bellow on https://www.bottlecaps.de/rr/ui on the tab Edit Grammar the click on the tab View Diagram to see/download a navigable railroad diagram.

/* converted on Sun Feb 26, 2023, 17:44 (UTC+01) by bison-to-w3c v0.62 which is Copyright (c) 2011-2022 by Gunther Rademacher <[email protected]> */
// From: https://github.com/UoYCS-plasma/GP2/blob/master/src/parser.y
Initialise
         ::= GP_PROGRAM Declaration+
           | GP_GRAPH HostGraph
           | GP_RULE RuleDecl
Declaration
         ::= MainDecl
           | ProcDecl
           | RuleDecl
MainDecl ::= MAIN '=' ComSeq
ProcDecl ::= ( ProcID '=' ( '[' LocalDecls ']' )? | RuleID '=' '[' LocalDecls ']' ) ComSeq
LocalDecls
         ::= ( RuleDecl | ProcDecl )*
ComSeq   ::= Command ( ( ';' | ',' ) Command )*
Command  ::= ( Block OR | IF Block ( THEN ( Block ELSE )? | ELSE ) | TRY ( Block THEN )? ( Block ELSE )? )? Block
Block    ::= ( '(' ComSeq ')' | SimpleCommand ) '!'?
           | error ')'
           | SKIP
           | FAIL
           | BREAK
SimpleCommand
         ::= RuleSetCall
           | RuleID
           | ProcID
RuleSetCall
         ::= ( '{' ( RuleID | ProcID ) ( ( ',' | ';' ) RuleID )* | error ) '}'
RuleDecl ::= ( RuleID '(' ( VarDecls ';'? )? | ProcID '(' VarDecls ) ')' Graph ARROW Graph Inter CondDecl
VarDecls ::= VarList ':' Type ( ';' VarList ':' Type )*
VarList  ::= Variable ( ',' Variable )*
Inter    ::= ( INTERFACE '=' '{' ( NodeID ( ',' NodeID )* )? | error ) '}'
Type     ::= INT
           | CHARACTER
           | STRING
           | ATOM
           | LIST
Graph    ::= '[' ( Position '|' )? ( '|' | NodeList '|' EdgeList? ) ']'
NodeList ::= Node+
Node     ::= '(' NodeID RootNode ',' Label Position? ')'
EdgeList ::= Edge+
Edge     ::= '(' EdgeID Bidirection ',' NodeID ',' NodeID ',' Label ')'
Position ::= '<' ( DNUM ',' ( DNUM | '-'? NUM ) | '-'? NUM ',' ( '-'? NUM | DNUM ) ) '>'
RootNode ::= ROOT?
Bidirection
         ::= BIDIRECTIONAL?
CondDecl ::= ( WHERE Condition )?
Condition
         ::= ( Subtype '(' Variable | EDGETEST '(' NodeID ',' NodeID LabelArg | '(' Condition ) ')'
           | List ( '=' | NEQ ) List
           | AtomExp ( '>' | GTEQ | '<' | LTEQ ) AtomExp
           | ( NOT | Condition ( OR | AND ) ) Condition
Subtype  ::= INT
           | CHARACTER
           | STRING
           | ATOM
LabelArg ::= ( ',' Label )?
Label    ::= List ( '#' ( MARK | ANY_MARK ) )?
List     ::= ( AtomExp | _EMPTY ) ( ':' ( AtomExp | _EMPTY ) )*
AtomExp  ::= Variable
           | NUM
           | STR
           | ( ( INDEG | OUTDEG ) '(' NodeID | _LENGTH '(' Variable | '(' AtomExp ) ')'
           | ( '-' | AtomExp ( '+' | '-' | '*' | '/' | '.' ) ) AtomExp
ProcID   ::= PROCID
RuleID   ::= ID
NodeID   ::= ID
           | NUM
EdgeID   ::= ID
           | NUM
Variable ::= ID
HostGraph
         ::= '[' ( Position '|' )? ( '|' | HostNodeList '|' HostEdgeList? ) ']'
HostNodeList
         ::= HostNode+
HostNode ::= '(' HostID RootNode ',' HostLabel Position? ')'
HostEdgeList
         ::= HostEdge+
HostEdge ::= '(' HostID ',' HostID ',' HostID ',' HostLabel ')'
HostID   ::= NUM
HostLabel
         ::= HostList ( '#' MARK )?
HostList ::= ( HostExp | _EMPTY ) ( ':' ( HostExp | _EMPTY ) )*
HostExp  ::= '-'? NUM
           | STR
	   
// Tokens
//\(\S+\)\s+return \(\S[^;]+\);

 /* GP2 keywords */ 
MAIN ::= "Main"
IF ::= "if"
TRY ::= "try"
THEN ::= "then"
ELSE ::= "else"
SKIP ::= "skip"
FAIL ::= "fail"
BREAK ::= "break"
WHERE ::= "where"
AND ::= "and"
OR ::= "or"
NOT ::= "not"
EDGETEST ::= "edge"
INDEG ::= "indeg"
OUTDEG ::= "outdeg"
INTERFACE ::= "interface"
_EMPTY ::= "empty"
_LENGTH ::= "length"

 /* Keywords for node and edge marks */
MARK ::= "red" | "green" |	 "blue" | "grey" | "dashed"
 /* Any has a distinct token since it cannot appear in the host graph and
    therefore must be distinguished from the other marks. */
ANY_MARK ::= "any"

 /* Keywords for GP2 types */
INT ::= "int"
CHARACTER ::= "char"
STRING ::= "string"  
ATOM ::= "atom"  
LIST ::= "list"  

ARROW ::= "=>"
ROOT ::= "(R)"
BIDIRECTIONAL ::= "(B)"
NEQ ::= "!=" 
GTEQ ::= ">=" 
LTEQ ::= "<=" 
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