-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbnf.txt
72 lines (60 loc) · 2.52 KB
/
bnf.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
;--CODENAME: raxacoricofallapatorius--
;--Program--
<program>::=<function>*
;--Basics--
<NUMBER>::=\d+
<IDENTIFIER>::=[a-zA-Z$][a-zA-Z0-9]
<STRING>::='"'([\w]^")'"'
;--Literal--
<int_literal>::=<NUMBER>
<double_literal>::=<int_literal>'.'<NUMBER>
<numeric_literals>::=<int_literal>|<double_literal>
<bool_literal>::='true'|'false'
<void_literals>::=;nothing xDD
<literals>::=<int_literal>|<double_literal>|<bool_literal>|<STRING>
;--Types--
<boolean_type>::='bool'
<string_type>::='str'
<void_type>::='void'
<numeric_types>::='int'|'double'
<array_types>::<numeric_types>|<boolean_type>|<string_type>
<var_types>::=<array_types>|<array_types>"[]"
<return_types>::<var_types>|<void_type>
;--Functions--
<function_declaration>::='func' <return_types> <IDENTIFIER>'('<list_of_parametrs>')'<comp_block>
<list_of_parametrs>::=<parametr>(','<parametr>)*
<parametr>::=<var_types> <IDENTIFIER>
<function_call>::='call' <IDENTIFIER>'('<IDENTIFIER>(','<IDENTIFIER>)*')'
<return>::='return' (<IDENTIFIER>|<expression>)?
;--Var--
<var_declaration>::=(<var_types> <IDENTIFIER>';')|(<var_types> <IDENTIFIER> '=' <literals>';')
<var_init>::=<IDENTIFIER> '=' <bool_expr>
<var_manipulation>::=<var_declaration>|<var_init>
;--Blocks--
<block_statments>::=<if>|<for>|<while>
<block>::='{'<com_block>*'}' | <comp_block>
<statement>::=<body>';'
<comp_block>::=<block_statments>|<block>|<statement>|<var_manipulation>
<body>::=<return>|<assignment>|<bool_expr>
;--Statements--
;----for
<for>::='for' '('<for_expr>?';'<bool_expr>?';'<for_expr>*')'<block>
<for_expr>::=<assignment>|<bool_expr>
;----if
<if>::=<if_only>|<if_else>
<if_only>::='if' '('<bool_expr>')' <block>
<if_else>::='if' '('<bool_expr>')' <block> 'else' <block>
;----while
<while>::='while' '('<bool_expr>')' <block>
;--Expresion--
<bool_expr>::=<bool_term>|<bool_term> '|' <bool_term>
<bool_term>::=<bool_not_factor> | <bool_not_factor> '&' <bool_term>
<bool_not_factor>::=<bool_factor> | '!'<bool_factor>
<bool_factor>::=<bin_expr>|<bin_expr> '!=' <bin_expr>|<bin_expr> '==' <bin_expr>|
<bin_expr> '>=' <bin_expr>|<bin_expr> '<=' <bin_expr>|
<bin_expr> '>' <bin_expr>|<bin_expr> '<' <bin_expr>|
<bin_expr>::=<bin_factor>|'-' <bin_factor>
<bin_factor>::=<term>|<term> '+' <term>|<term> '-' <term>
<term>::=<sign_factor>|<sign_factor> '*' <sign_factor>|<sign_factor> '/' <sign_factor>|<sign_factor> 'div' <sign_factor>|<sign_factor> 'mod' <sign_factor>
<sign_factor>::=<numeric_literals> |'-' <numeric_literals> | <unsign_factor>
<unsign_factor>::='(' <bin_factor>')' | <IDENTIFIER> | <STRING> | <bool_literal>