-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsyntax.txt
64 lines (42 loc) · 1.81 KB
/
syntax.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
program -> declaration* ;
--- Statements ---
declaration -> '$' IDENTIFIER ( '=' expr )?
| statement ;
statement -> '|-' expr expr?
| '{' declaration* '}'
| 'break' | 'continue'
| expr
| 'for' declaration? ',' expr? ',' expr? statement
| 'forever' statement
| 'goto' IDENTIFIER
| 'if' expr statement ( 'else' statement )?
| 'print' expr?
| 'while' expr statement ;
--- Expressions ---
expr -> assignment ;
assignment -> ternary ( ( '=' | '+=' | '-=' | '*=' | '/=' | '%=' | '^=' ) assignment )? ;
ternary -> or_expr ( '?' expr ':' expr )? ;
or_expr -> and_expr ( 'or' and_expr )* ;
and_expr -> equality ( 'and' equality )* ;
equality -> comparison ( ( '==' | '!=' ) comparison )* ;
comparison -> sum ( ( '<' | '<=' | '>' | '>=' ) sum )* ;
sum -> term ( ( '+' | '-' ) term )* ;
term -> unary ( ( '*' | '/' | '%' ) unary)* ;
unary -> ( '-' | '+' | '!' ) unary
| power ;
power -> factorial ( '^' unary)* ;
factorial -> call '!'* ;
call -> atom ( ( '[' expr ']' ) )* ;
atom -> '(' expr ')'
| 'in' expr?
| INT
| FLOAT
| STRING
| 'tru'
| 'fls'
| 'nul'
| IDENTIFIER ':'?
FLOAT -> INT '.' INT ;
INT -> [0-9]+ ;
IDENTIFIER -> [A-Za-z_][A-Za-z0-9_]* ;
STRING -> ('"' | ''') (any ascii character including escape)* ('"' | ''') ;