Skip to content

Grammar railroad diagram #9

@mingodad

Description

@mingodad

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      ::= $

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions