-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaplang-lite-syntax.txt
46 lines (35 loc) · 2.48 KB
/
aplang-lite-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
program → use_decl* declaration* ;
declaration → class_decl | fun_decl | var_decl ;
class_decl → "class" IDENTIFIER (":" type ("," type)*)? "{" program "}" ;
fun_decl → "fn" IDENTIFIER "(" ( IDENTIFIER ":" type ( "," IDENTIFIER ":" type)* )? ")" ( ":" type )? block ;
var_decl → "var" IDENTIFIER ( ":" type )? ( "=" expression )? "\n" ;
use_decl → "use" IDENTIFIER ( "." IDENTIFIER)* ( "." "*" | "as" IDENTIFIER)? "\n" ;
statement → for_stmt | return_stmt | break_stmt | while_stmt | var_decl | if_stmt | block | exp_stmt ;
for_stmt → "for" "(" IDENTIFIER ":" type ":" expression ")" statement ;
return_stmt → "return" expression? "\n" ;
break_stmt → "break" "\n" ;
while_stmt → "while" "(" expression ")" statement ;
if_stmt → "if" "(" expression ")" statement ( "else" statement )? ;
exp_stmt → expression "\n" ;
expression → assignment ;
assignment → call ( "+=" | "-=" | "*=" | "**=" | "/=" | "%=" | "&=" | "|=" | "^=" | "~=" | "<<=" | ">>=" | ">>>=" | "=")
assignment | if_expr ;
if_expr → "if" "(" expression ")" expression ( "else" expression ) ;
logic_or → logic_and ( "||" logic_and )* ;
logic_and → equality ( "&&" equality )* ;
equality → comparison ( ( "!=" | "==" ) comparison )* ;
comparison → term ( ( ">" | ">=" | "<" | "<=" ) term )* ;
term → factor ( ( "-" | "+" ) factor )* ;
factor → bit_op ( ( "/" | "*" | "**" | "%" ) bit_op )* ;
bit_op → unary_left ( ( "|" | "^" | "&" | ">>" | "<<" | ">>>" ) unary_left )* ;
unary_left → ( "!" | "~" | "-" ) unary_left | call ;
oop → call ( "as" | "is" ) type;
call → ( primary | IDENTIFIER func_args?) ("." IDENTIFIER func_args? ) ;
primary → LITERAL | VALUE_TOKEN | IDENTIFIER | "(" expression ")" ;
block → "{" (var_decl | statement)* "}" ;
type → path ; // Generics ??
path → IDENTIFIER ( "." IDENTIFIER)* ;
func_args → "(" (expression ( "," expression )*)? ")"
VALUE_TOKEN → "null" | "this" | "super"
LITERAL → NUMBER | STRING | CHAR ;
NUMBER → #"0x[0-9a-fA-F]+" | #"0b[0-1]+" | #"[0-9]+(?:\.[0-9]+)" ;