-
Notifications
You must be signed in to change notification settings - Fork 0
/
bnf
106 lines (79 loc) · 1.68 KB
/
bnf
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
104
105
106
//Program initialization
<program>:
<main_function>
| <function> <program>
<main_function>: init(){<stmts>}
<function>: func IDENTIFIER (<argument_list>){<stmts><RETURN_stmt>}
<stmts>:
<stmt>
| <stmt> <stmts>
<stmt>:
<matched>
| <unmatched>
<matched>:
if(<logic_expr>)<matched> else <matched>
| <nonif_stmt>
<unmatched>:
if(<logic_expr>)<stmt>
| if(<logic_expr>)<matched> else <unmatched>
<nonif_stmt>:
/* nothing */
| <RETURN_stmt>
| <assign_stmt> //var, val , boolean assignments etc. etc.
| <print_stmt>
| <input_stmt>
| <while_stmt>
| <comment_stmt>
<assign_stmt>:
<variable> = <boolean_expr>
| <variable> = <logic_expr>
<print_stmt>:
print LP <IDENTIFIER> RP
| print LP <variable> RP
<input_stmt>:
input <variable> = boolean_expr
//User can only input true or false
<RETURN_stmt>:
RETURN <boolean_expr>
| RETURN <variable>
<comment_stmt>:
comment
//LOOPS
<while_stmt>: <while> LP <logic_expr> RP LCB <stmts> RCB
<logic_expr>:
<logic_implies>
<logic_implies>:
<logic_or>
| <logic_implies> IMPLIES <logic_or>
<logic_or>:
<logic_and>
| <logic_or> OR <logic_and>
<logic_and>:
<logic_negate>
| <logic_and> AND <logic_negate>
<logic_negate>:
<logic_parantesis>
| NEGATION<logic_negate>
<logic_parantesis>:
<logic_expr>
| ( <logic_parantesis> )
| <variable>
| boolean_expr
| <const>
//logic expression end
<argument_list>:
/* nothing */
| <variable>
| <const>
| <variable> , <argument_list>
| <const> , <argument_list>
<variable>:
VAR IDENTIFIER
<const>:
VAL IDENTIFIER
<IDENTIFIER>:
STRING//Defined in lex
//NONTERMINALS
boolean_expr:
TRUE
| FALSE