-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgrammar.txt
100 lines (74 loc) · 4.09 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
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
This is the syntax of the Nougaro language. This file is not actually parsed by Nougaro, but is rather a way to explain the syntax.
statements : NEWLINE* statement (NEWLINE+ statement)* NEWLINE*
statement : KEYWORD:RETURN expr?
: KEYWORD:IMPORT IDENTIFIER (DOT IDENTIFIER)?* (KEYWORD:AS IDENTIFIER)?
: KEYWORD:EXPORT expr AS IDENTIFIER
: KEYWORD:EXPORT IDENTIFIER (KEYWORD:AS IDENTIFIER)?
: KEYWORD:CONTINUE (COLON IDENTIFIER)?
: KEYWORD:BREAK (COLON IDENTIFIER)? (KEYWORD:AND KEYWORD:RETURN expr)?
: expr
expr : var_assign
: KEYWORD:DEL IDENTIFIER
: KEYWORD:WRITE expr (TO|TO_AND_OVERWRITE) expr INT?
: KEYWORD:READ expr (TO IDENTIFIER)? INT?
: KEYWORD:ASSERT expr (COMMA expr)?
: comp_expr ((KEYWORD:AND|KEYWORD:OR|KEYWORD:XOR|BITWISEAND|BITWISEOR|BITWISEXOR) comp_expr)*
var_assign : KEYWORD:VAR assign_id (COMMA assign_id)?* assign_eq assign_expr
: KEYWORD:VAR assign_id (INCREMENT|DECREMENT)
assign_id : (IDENTIFIER (LPAREN NEWLINE?* (MUL? expr (COMMA NEWLINE?* MUL? expr)?*)? NEWLINE?* RPAREN)?* DOT)?* IDENTIFIER
assign_eq : EQ|PLUSEQ|MINUSEQ|MULTEQ|DIVEQ|POWEQ|FLOORDIVEQ|PERCEQ|OREQ|ANDEQ|XOREQ|BITWISEANDEQ|BITWISEOREQ|BITWISEXOREQ|EEEQ|GTEQ|GTEEQ|LTEQ|LTEEQ
assign_expr : expr (COMMA expr)?*
comp_expr : (KEYWORD:NOT|BITWISENOT) comp_expr
: arith_expr ((EE|LT|GT|LTE|GTE|KEYWORD:IN) arith_expr)*
arith_expr : term ((PLUS|MINUS) term)*
term : factor ((MUL|DIV|PERC|FLOORDIV) factor)*
factor : (PLUS|MINUS) factor
: LEGACYABS factor LEGACYABS
: power
power : call (DOT call)?* (POW factor)*
call : atom (LPAREN NEWLINE?* (MUL? expr (COMMA NEWLINE?* MUL? expr)?*)? NEWLINE?* RPAREN)?*
atom : (INT|FLOAT)(E_INFIX INT)?
: STRING (STRING NEWLINE?*)?*
: IDENTIFIER (INTERROGATIVE_PNT IDENTIFIER|expr)?*
: LPAREN NEWLINE? expr NEWLINE? RPAREN
: DOLLAR IDENTIFIER
: list_expr
: if_expr
: for_expr
: while_expr
: do_expr
: loop_expr
: func_def
: class_def
: <default>
list_expr : LSQUARE NEWLINE?* (MUL? expr (COMMA NEWLINE?* MUL? expr)?*)? NEWLINE?* RSQUARE
if_expr : KEYWORD:IF expr KEYWORD:THEN
((statement if_expr_b|if_expr_c?)
| (NEWLINE statements KEYWORD:END|if_expr_b|if_expr_c))
if_expr_b : KEYWORD:ELIF expr KEYWORD:THEN
((statement if_expr_b|if_expr_c?)
| (NEWLINE statements KEYWORD:END|if_expr_b|if_expr_c))
if_expr_c : KEYWORD:ELSE
(statement
| (NEWLINE statements KEYWORD:END))
for_expr : KEYWORD:FOR (COLON IDENTIFIER)?
IDENTIFIER EQ expr KEYWORD:TO expr (KEYWORD:STEP expr)? KEYWORD:THEN
statement | (NEWLINE statements KEYWORD:END)
: KEYWORD:FOR (COLON IDENTIFIER)?
IDENTIFIER KEYWORD:IN expr KEYWORD:THEN
statement | (NEWLINE statements KEYWORD:END)
while_expr : KEYWORD:WHILE (COLON IDENTIFIER)?
expr KEYWORD:THEN
statement | (NEWLINE statements KEYWORD:END)
do_expr : KEYWORD:DO (COLON IDENTIFIER)?
(statement | (NEWLINE statements)) KEYWORD:THEN KEYWORD:LOOP KEYWORD:WHILE expr
loop_expr : KEYWORD:LOOP (COLON IDENTIFIER)?
statement | (NEWLINE statements KEYWORD:END)
func_def : KEYWORD:DEF IDENTIFIER? func_def_args optional_func_def_args?
(ARROW expr)|(NEWLINE statements KEYWORD:END)
func_def_args : LPAREN NEWLINE?* (IDENTIFIER (COMMA NEWLINE?* IDENTIFIER)*?)? NEWLINE*? RPAREN
optional_func_def_args : LPAREN NEWLINE?* IDENTIFIER EQ expr (COMMA NEWLINE?* IDENTIFIER EQ expr)*? NEWLINE?* RPAREN
class_def : KEYWORD:CLASS IDENTIFIER?
(LPAREN NEWLINE?* IDENTIFIER? NEWLINE?* RPAREN)?
(ARROW expr)
| (NEWLINE statements KEYWORD:END)