Skip to content

Commit 17649a5

Browse files
Update grammar.md
1 parent f8f1a01 commit 17649a5

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

grammar.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,33 @@
1+
```
2+
(*
3+
YASL uses a variant of EBNF in its documentation to specify the grammar.
4+
- Non-terminals are specified with bare identifiers: example.
5+
- Terminals are specified with double-quotes: "example".
6+
- An asterisk [*] means the previous expression is repeated 0 or more times: "0"*
7+
- A comma followed by an asterisk [,*] means the previous expression is repeated 0 or more times, separated by a comma: ID,*
8+
- A postfix question mark [?] means the previous expression is optional: "const"?
9+
- Parentheses [(...)] may be used to group expressions: ("const"? ID),*
10+
- A pipe [|] represents alternatives: "let" | "const"
11+
- Question marks on both sides [?...?] represent a special sequence, normally one that is obvious but tedious to write out: ?keyword?\
12+
- Front-slashes on both sides represent a regex: /[A-Za-z_$][A-Za-z0-9_$]*/
13+
- A minus sign [-] omits the expressions on the right from the expression on the left, even if they would normally match. The only special characters for regex are brackets for character classes, plus for 1 or more occurances, and asterisk for 0 or more occurances: /[A-Za-z_$][A-Za-z0-9_$]*/ - ?keyword?
14+
- Each production rule is terminated by a semicolon [;]
15+
- When a literal semicolon is used in a rule, it may be substituted for a newline in a YASL program
16+
*)
117
18+
19+
program = stmt*;
20+
stmt = expr_stmt | if_stmt | while_stmt | for_stmt | assert_stmt | match_stmt | export_stmt | let_stmt | const_stmt;
21+
expr_stmt = expr ";";
22+
expr = "undef" | bool_expr | int_expr | float_expr | str_expr | list_expr | table_expr | fn_expr;
23+
bool_expr = "true" | "false";
24+
int_expr = /0x[0-9a-fA-F_]+/ - /0x_+/ | /[0-9][0-9_]*/ | /0b[01_]+/ - /0b_+/;
25+
float_expr = /[0-9][0-9_]*.[0-9][0-9_]/;
26+
str_expr = "." id | /`[^`]`/ | ?single quoted strings with escapes? | ?double quoted strings with escapes and interpolation?;
27+
list_expr = "[" expr,* "]" | "[" expr "for" id "<-" expr ("if" expr)? "]";
28+
table_expr = "{" (expr ":" expr),* "}" | "{" expr ":" expr "for" id "<-" expr (if expr)? "}";
29+
fn_expr = "fn" "(" ("const"? id),* ")" "{" (stmt | "return" expr)* "}";
30+
31+
32+
33+
```

0 commit comments

Comments
 (0)