-
Notifications
You must be signed in to change notification settings - Fork 0
/
fleaux_grammar.pg
103 lines (82 loc) · 2.21 KB
/
fleaux_grammar.pg
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
program:
statement_list?;
statement_list:
statement+;
statement:
(let_statement | expression_statement) ';';
let_statement:
LET identifier '(' parameter_decl_list ')' ':' type LET_EXPR_SEPARATOR expression;
expression_statement:
expression;
parameter_decl_list:
parameter+[COMMA];
parameter:
identifier ':' type;
tuple_type:
type_list;
type_list:
type+[COMMA];
type:
NUMBER | STRING | BOOL | NULL | ANY | identifier | '(' type_list ')';
expression:
constant |
identifier |
'(' expression ')' |
expression PIPELINE_OPERATOR expression {left, 10} |
expression PLUS_OPERATOR expression {left, 5} |
expression MINUS_OPERATOR expression {left, 5} |
expression DIVIDE_OPERATOR expression {left, 6} |
expression MULTIPLY_OPERATOR expression {left, 6} |
expression MODULUS_OPERATOR expression {left, 6} |
expression EXPONENT_OPERATOR expression {right, 7} |
expression EQ_OPERATOR expression {left, 4} |
expression NE_OPERATOR expression {left, 4} |
expression LT_OPERATOR expression {left, 4} |
expression GT_OPERATOR expression {left, 4} |
expression GE_OPERATOR expression {left, 4} |
expression LE_OPERATOR expression {left, 4} |
expression OR_OPERATOR expression {left, 1} |
expression AND_OPERATOR expression {left, 2} |
expression COMMA expression {left, 1} |
NOT_OPERATOR expression {right, 3} |
PLUS_OPERATOR expression {right, 1} |
MINUS_OPERATOR expression {right, 1};
identifier:
ID;
constant:
NUMERICAL_CONSTANT | STRING_LITERAL | TRUE | FALSE | NULL;
LAYOUT: LayoutItem | LAYOUT LayoutItem | EMPTY;
LayoutItem: WS | Comment;
terminals
NUMERICAL_CONSTANT:
/-?\d+(\.\d+)?(e|E[-+]?\d+)?/;
STRING_LITERAL: /"((\\")|[^"])*"/;
ID: /[a-zA-Z_][a-zA-Z_0-9]*/;
PIPELINE_OPERATOR: "->";
LE_OPERATOR: "<=";
GE_OPERATOR: ">=";
EQ_OPERATOR: "==";
NE_OPERATOR: "!=";
LT_OPERATOR: "<";
GT_OPERATOR: ">";
AND_OPERATOR: "&&";
OR_OPERATOR: "||";
PLUS_OPERATOR: "+";
MINUS_OPERATOR: "-";
DIVIDE_OPERATOR: "/";
MULTIPLY_OPERATOR: "*";
MODULUS_OPERATOR: "%";
EXPONENT_OPERATOR: "^";
NOT_OPERATOR: "!";
LET_EXPR_SEPARATOR: "::";
LET: "let";
NUMBER: "Number";
STRING: "String";
BOOL: "Bool";
NULL: "Null";
TRUE: "True";
FALSE: "False";
ANY: "Any";
COMMA: ',';
WS: /\s+/;
Comment: /\/\/.*/;