-
Notifications
You must be signed in to change notification settings - Fork 1
/
grammar.txt
62 lines (45 loc) · 2.23 KB
/
grammar.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
file : statements*
statement : ((expr | ret ) ';') | branching | block;
seperate by \n
expr : nr_expr |
infix_call ;
nr_expr : '(' expr ')' |
assignment |
block |
call |
literal |
identifier ;
ret : 'ret' expr ;
branching : branching_if | branching_while;
branching_if : 'if' '(' expr ')' positive ('else' negative)? ;
positive : statement ;
negative : statement ;
branching_while : 'while' '(' expr ')' statement ;
assignment : assignment_left '=' assignment_right ;
assignment_left : identifier |
variable_decl |
function_decl ;
assignment_right : expr;
variable_decl : 'let' identifier ;
identifier_list : (identifier ',')* identifier ;
function_decl : 'let' identifier '(' identifier_list? ')' ;
infix_call : infix_call_left identifier infix_call_right ;
infix_call_left : nr_expr ;
infix_call_right : expr ;
argument_list : (expr ',')* expr ;
call : identifier '(' argument_list? ')' ;
block : '{' (statement | COMMENT)* '}' ;
literal : type_float |
type_int |
type_bool |
type_string ;
type_float : FLOAT ;
type_int : INTEGER ;
type_bool : BOOL ;
type_string : STRING ;
FLOAT : [0-9]+ '.' [0-9]+ ;
INTEGER : [0-9]+ ;
STRING : '"' [a-zA-Z0-9]* '"' ;
BOOL : 'true' | 'false' ;
identifier : IDENTIFIER ;
IDENTIFIER : Alpha+(Numeric|Alpha)* ;