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

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

Grammar railroad diagram #9

mingodad opened this issue Sep 19, 2024 · 0 comments

Comments

@mingodad
Copy link

Using this https://github.com/GuntherRademacher/ebnf-convert and https://github.com/GuntherRademacher/rr we can generate a nice navigable railroad diagram for Numscript grammar (see bellow instructions at the top).

/* converted on Thu Sep 19, 2024, 22:57 (UTC+02) by antlr_4-to-w3c v0.68-SNAPSHOT which is Copyright (c) 2011-2024 by Gunther Rademacher <grd@gmx.net> */
//
// 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.
//

program  ::= varsDeclaration? statement* EOF

monetaryLit
         ::= '[' literal literal ']'
portion  ::= RATIO_PORTION_LITERAL
           | PERCENTAGE_PORTION_LITERAL
literal  ::= ASSET
           | STRING
           | ACCOUNT
           | VARIABLE_NAME
           | NUMBER
           | monetaryLit
           | portion
functionCallArgs
         ::= literal ( ',' literal )*
functionCall
         ::= IDENTIFIER '(' functionCallArgs? ')'
varOrigin
         ::= '=' functionCall
varDeclaration
         ::= IDENTIFIER VARIABLE_NAME varOrigin?
varsDeclaration
         ::= 'vars' '{' varDeclaration* '}'
sentAllLit
         ::= '[' literal '*' ']'
cap      ::= monetaryLit
           | VARIABLE_NAME
allotment
         ::= portion
           | VARIABLE_NAME
           | 'remaining'
source   ::= literal ( 'allowing' ( 'unbounded' 'overdraft' | 'overdraft' 'up' 'to' literal ) )?
           | '{' ( allotmentClauseSrc* | source+ ) '}'
           | 'max' cap 'from' source
allotmentClauseSrc
         ::= allotment 'from' source
keptOrDestination
         ::= 'to' destination
           | 'kept'
destinationInOrderClause
         ::= 'max' literal keptOrDestination
destination
         ::= literal
           | '{' ( allotmentClauseDest+ | destinationInOrderClause* 'remaining' keptOrDestination ) '}'
allotmentClauseDest
         ::= allotment keptOrDestination
sentValue
         ::= literal
           | sentAllLit
statement
         ::= 'send' sentValue '(' 'source' '=' source 'destination' '=' destination ')'
           | functionCall
_        ::= WS
           | MULTILINE_COMMENT
           | LINE_COMMENT
          /* ws: definition */

<?TOKENS?>

WS       ::= [ #x9#xd#xa]+
NEWLINE  ::= [#xd#xa]+
MULTILINE_COMMENT
         ::= '/*' ( MULTILINE_COMMENT | . )* '*/'
LINE_COMMENT?
         ::= '//' .* NEWLINE
RATIO_PORTION_LITERAL
         ::= [0-9]+ ' '? '/' ' '? [0-9]+
PERCENTAGE_PORTION_LITERAL
         ::= [0-9]+ ( '.' [0-9]+ )? '%'
STRING   ::= '"' ( '\"' | [^"#xd#xa] )* '"'
IDENTIFIER
         ::= [a-z]+ [a-z_]*
NUMBER   ::= [0-9]+
VARIABLE_NAME
         ::= '$' [a-z_]+ [a-z0-9_]*
ACCOUNT  ::= '@' [a-zA-Z0-9_#x2D] ( ':'? [a-zA-Z0-9_#x2D] )*
ASSET    ::= [A-Z/0-9]+
EOF      ::= $
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