Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

BNF Grammar

This is the complete formal grammar for Convex-λ in Backus-Naur Form.

Program Structure

<program>       ::= <statement>*

<statement>     ::= <import>
                  | <export>
                  | <assignment>
                  | <config>
                  | <expression>
                  | <comment>

Import and Export

<import>        ::= "import" <import_list> "from" <string>
<import_list>   ::= <identifier> ("," <identifier>)* ["as" <identifier>]

<export>        ::= "export" <identifier_list>
<identifier_list> ::= <identifier> ("," <identifier>)*

Assignments

<assignment>    ::= <identifier> "=" <expression>   # variable binding
                  | <identifier> ":=" <expression>  # renderable output

Configuration

<config>        ::= "Gear" "(" <number> ")"
                  | "Mode" "(" <string> ")"
                  | "RI" "(" <number> ")"

Expressions

<expression>    ::= <ternary>

<ternary>       ::= <logical_or> ("?" <expression> ":" <expression>)?

<logical_or>    ::= <logical_and> ("||" <logical_and>)*
<logical_and>   ::= <equality> ("&&" <equality>)*

<equality>      ::= <comparison> (("==" | "!=") <comparison>)*
<comparison>    ::= <term> (("<" | ">" | "<=" | ">=") <term>)*

<term>          ::= <factor> (("+" | "-") <factor>)*
<factor>        ::= <power> (("*" | "/" | "%") <power>)*

<power>         ::= <unary> ("^" <power>)?
<unary>         ::= ("!" | "-" | "?")? <pipe>

<pipe>          ::= <postfix> (("|>" | "?|") <postfix>)*
<postfix>       ::= <primary> <postfix_op>*

<postfix_op>    ::= "." <identifier>          # property access
                  | "(" <arg_list>? ")"        # function call
                  | "[" <expression> "]"       # index access
                  | ">>" <expression>          # index shorthand

Primary Expressions

<primary>       ::= <number>
                  | <string>
                  | <identifier>
                  | <array>
                  | <lambda>
                  | <fold>
                  | <constructor_call>
                  | "(" <expression> ")"

<array>         ::= "[" (<expression> ("," <expression>)*)? "]"

<lambda>        ::= <identifier> "=>" <expression>
                  | "(" <param_list>? ")" "=>" <expression>

<fold>          ::= "fold" "(" <expression> "," <expression> "," <expression> ")"

Constructors

<constructor_call> ::= "n" "(" <expression> "," <expression> ")"
                     | "p" "(" <expression> "," <expression> "," <expression> ")"
                     | "v" "(" <expression> "," <expression> "," <expression> ")"
                     | "P" "(" <expression> "," <expression> ")"
                     | "l" "(" <expression> "," <expression> ")"
                     | "Rot" "(" <expression> "," <expression> ")"
                     | "Mir" "(" <expression> ")"
                     | "Hull" "(" <expression> ")"

Literals

<number>        ::= <float> <opt_hint>?
<opt_hint>      ::= <range_hint> | <delta_hint>
<range_hint>    ::= <float> ".." <float>
<delta_hint>    ::= ("+/-" | "±") <float> "%"?

<string>        ::= '"' <char>* '"'

<identifier>    ::= <letter> (<letter> | <digit> | "_")*

<letter>        ::= "a".."z" | "A".."Z" | "_"
<digit>         ::= "0".."9"

Comments

<comment>       ::= "//" <any>* <newline>
                  | "/*" <any>* "*/"

Built-in Constants

<constant>      ::= "PI" | "PHI" | "RI" | "true" | "false"

Operators Summary

CategoryOperators
Arithmetic+, -, *, /, %, ^
Comparison==, !=, <, >, <=, >=
Logical&&, ||, !
Assignment=, :=
Pipe|>, `?
Geometric:, ->, *>
Access., >>, []
Lambda=>
Range..