Skip to content

Grammar railroad diagram #32

@mingodad

Description

@mingodad

Asking copilot to extract an ebnf for railroad diagram form this project gave the EBNF shown bellow that seems a good start to manually fix the missing pieces for documentation/development/debug (see instructions at the top).

//
// 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.
//

/* DSLCad Language EBNF for Railroad Diagrams */

program           ::= statement*

statement         ::= variable_statement | return_statement

variable_statement ::= "var" identifier ( "=" expression )? ";"

return_statement  ::= expression ";"

expression        ::= or_expr

or_expr           ::= and_expr ( "or" and_expr )*

and_expr          ::= equality_expr ( "and" equality_expr )*

equality_expr     ::= comparison_expr ( ( "==" | "!=" ) comparison_expr )*

comparison_expr   ::= addsub_expr ( ( "<" | "<=" | ">" | ">=" ) addsub_expr )*

addsub_expr       ::= muldivmod_expr ( ( "+" | "-" ) muldivmod_expr )*

muldivmod_expr    ::= pow_expr ( ( "*" | "/" | "%" ) pow_expr )*

pow_expr          ::= inject_expr ( "**" inject_expr )*

inject_expr       ::= spanning_expr ( "->" identifier? spanning_expr )*

spanning_expr     ::= terminal_expr ( ( "(" call_arguments? ")" )
                                   | ( "." identifier )
                                   | ( "[" expression "]" ) )*

terminal_expr     ::= ( "-" terminal_expr )
                   | ( "not" terminal_expr )
                   | number
                   | bool
                   | string
                   | call
                   | reference
                   | "(" expression ")"
                   | list_literal
                   | scope_expression
                   | function_literal
                   | map_expression
                   | reduce_expression
                   | if_expression

call              ::= path call_arguments
                   | path "(" ")"

call_arguments    ::= argument ( "," argument )*

argument          ::= identifier "=" expression | expression

reference         ::= identifier

list_literal      ::= "[" ( expression ( "," expression )* )? "]"

scope_expression  ::= "{" statement* "}"

function_literal  ::= "func" "{" statement* "}"

map_expression    ::= "map" expression "as" identifier ":" expression

reduce_expression ::= "reduce" expression ( "from" expression )? "as" identifier "," identifier ":" expression

if_expression     ::= "if" expression ":" expression "else" ( ":" expression | if_expression )

identifier        ::= /* see lexer */
number            ::= /* see lexer */
string            ::= /* see lexer */
bool              ::= "true" | "false"
path              ::= /* see lexer */

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions