doc: add full EBDF grammar
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
/* FZL (FromZero Language) syntax */
|
||||
/* Version 1 */
|
||||
/* Authors: */
|
||||
/* - Samsonium (https://git.samsonium.dev/Samsonium) */
|
||||
|
||||
<program> ::= <_> <statement>+
|
||||
|
||||
<statement> ::= <class_stmt>
|
||||
| <fn_stmt>
|
||||
| <if_stmt>
|
||||
| <block_stmt>
|
||||
| <ret_stmt>
|
||||
| <expr_stmt>
|
||||
|
||||
<_> ::= " "*
|
||||
<ws> ::= " "+
|
||||
|
||||
<expr_stmt> ::= <expr> <_> ";" <_>
|
||||
<block_stmt> ::= "{" <_> <statement>* "}" <_>
|
||||
<ret_stmt> ::= "return" (<ws> <expr>)? <_> ";" <_>
|
||||
|
||||
<class_stmt> ::= "class" <ws> <name> <_> "{" <_> (<declaration> | <fn_stmt>)* "}" <_>
|
||||
<fn_stmt> ::= "fn" <ws> <name> <_> "(" <_> (<param> (<_> "," <_> <param>)*)? ")" <_> <block_stmt>
|
||||
<param> ::= <type> <ws> <name>
|
||||
|
||||
<if_stmt> ::= "if" <_> "(" <_> <expr> <_> ")" <_> <statement> (<_> "else" <ws> <statement>)?
|
||||
|
||||
/* Assign (lowest epxression priority, right-associative) */
|
||||
<expr> ::= <assign_expr>
|
||||
<assign_expr> ::= <new_expr> (<_> "=" <_> <assign_expr>)?
|
||||
<new_expr> ::= ("new" <ws> <name>) | <or_expr>
|
||||
<or_expr> ::= <and_expr> (<_> "||" <_> <and_expr>)*
|
||||
<and_expr> ::= <cond_expr> (<_> "&&" <_> <cond_expr>)*
|
||||
<cond_expr> ::= <term_expr> (<_> <cond_op> <_> <term_expr>)*
|
||||
<cond_op> ::= "==" | "!=" | "<=" | ">=" | "<" | ">"
|
||||
|
||||
<term_expr> ::= <factor_expr> (<_> ("+" | "-") <_> <factor_expr>)*
|
||||
<factor_expr> ::= <power_expr> (<_> ("*" | "/" | "%") <_> <power_expr>)*
|
||||
<power_expr> ::= <unary_expr> (<_> "^" <_> <power_expr>)?
|
||||
<unary_expr> ::= (("!" | "-" | "+") <_>)* <postfix_expr>
|
||||
|
||||
/* Postfix: chain of calls and dots */
|
||||
<postfix_expr> ::= <primary_expr> (<call_suffix> | <member_suffix>)*
|
||||
<call_suffix> ::= <_> "(" <_> (<expr> (<_> "," <_> <expr>)*)? <_> ")"
|
||||
<member_suffix> ::= <_> "." <_> <name>
|
||||
|
||||
<primary_expr> ::= <literal>
|
||||
| <declaration>
|
||||
| "(" <_> <expr> <_> ")"
|
||||
| <name>
|
||||
|
||||
<declaration> ::= <type> <ws> <name>
|
||||
|
||||
<type> ::= "int" | "uint" | "bool" | "char" | "str"
|
||||
| "i8" | "i16" | "i32" | "i64"
|
||||
| "u8" | "u16" | "u32" | "u64"
|
||||
|
||||
<literal> ::= <number> | <string_literal> | "true" | "false" | "null"
|
||||
<name> ::= ([A-z] | "_") | ([A-z] | [0-9] | "_")*
|
||||
<string_literal> ::= ('"' [^"]* '"') | ("'" [^']* "'")
|
||||
|
||||
Reference in New Issue
Block a user