-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGrammar.txt
134 lines (134 loc) · 4.06 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
NonTerminal($):
$ → [ GLOBAL_STATEMENTS ]
NonTerminal(BLOCK):
BLOCK → [ { STATEMENTS } ]
BLOCK → [ { } ]
NonTerminal(STATEMENT):
STATEMENT → [ DECL ; ]
STATEMENT → [ ASSIGN ; ]
STATEMENT → [ EXPR_L1 ; ]
STATEMENT → [ LOGIC_EXPR_L1 ; ]
STATEMENT → [ IF ]
STATEMENT → [ LOOP ]
STATEMENT → [ RETURN ; ]
STATEMENT → [ break ; ]
STATEMENT → [ continue ; ]
NonTerminal(STATEMENTS):
STATEMENTS → [ STATEMENT ]
STATEMENTS → [ STATEMENTS STATEMENT ]
NonTerminal(GLOBAL_STATEMENT):
GLOBAL_STATEMENT → [ DECL ; ]
GLOBAL_STATEMENT → [ ASSIGN ; ]
GLOBAL_STATEMENT → [ EXPR_L1 ; ]
GLOBAL_STATEMENT → [ LOGIC_EXPR_L1 ; ]
GLOBAL_STATEMENT → [ FUNC ]
GLOBAL_STATEMENT → [ IF ]
GLOBAL_STATEMENT → [ LOOP ]
GLOBAL_STATEMENT → [ STRUCT ]
NonTerminal(GLOBAL_STATEMENTS):
GLOBAL_STATEMENTS → [ GLOBAL_STATEMENT ]
GLOBAL_STATEMENTS → [ GLOBAL_STATEMENTS GLOBAL_STATEMENT ]
NonTerminal(RETURN):
RETURN → [ return ]
RETURN → [ return EXPR_L1 ]
RETURN → [ return LOGIC_EXPR_L1 ]
NonTerminal(DECL):
DECL → [ TYPE identifier = EXPR_L1 ]
DECL → [ TYPE identifier = LOGIC_EXPR_L1 ; ]
NonTerminal(ASSIGN):
ASSIGN → [ LHS = EXPR_L1 ]
ASSIGN → [ LHS = LOGIC_EXPR_L1 ]
NonTerminal(FUNC):
FUNC → [ func identifier ( PARAMS ) = TYPE BLOCK ]
FUNC → [ func identifier ( PARAMS ) BLOCK ]
FUNC → [ func identifier ( ) = TYPE BLOCK ]
FUNC → [ func identifier ( ) BLOCK ]
NonTerminal(PARAMS):
PARAMS → [ TYPE identifier ]
PARAMS → [ PARAMS , TYPE identifier ]
NonTerminal(STRUCT):
STRUCT → [ struct identifier { STRUCT_FIELDS } ]
NonTerminal(STRUCT_FIELDS):
STRUCT_FIELDS → [ STRUCT_FIELD ]
STRUCT_FIELDS → [ STRUCT_FIELDS STRUCT_FIELD ]
NonTerminal(STRUCT_FIELD):
STRUCT_FIELD → [ TYPE identifier ; ]
NonTerminal(CALL):
CALL → [ identifier ( ARGS ) ]
CALL → [ identifier ( ) ]
CALL → [ builtin ( ARGS ) ]
CALL → [ builtin ( ) ]
NonTerminal(ARGS):
ARGS → [ ARG ]
ARGS → [ ARGS , ARG ]
NonTerminal(ARG):
ARG → [ EXPR_L1 ]
ARG → [ LOGIC_EXPR_L1 ]
NonTerminal(LOGIC_EXPR_L1):
LOGIC_EXPR_L1 → [ LOGIC_EXPR_L2 ]
LOGIC_EXPR_L1 → [ LOGIC_EXPR_L1 or LOGIC_EXPR_L2 ]
NonTerminal(LOGIC_EXPR_L2):
LOGIC_EXPR_L2 → [ LOGIC_EXPR_L3 ]
LOGIC_EXPR_L2 → [ LOGIC_EXPR_L2 and LOGIC_EXPR_L3 ]
NonTerminal(LOGIC_EXPR_L3):
LOGIC_EXPR_L3 → [ not ( LOGIC_EXPR_L1 ) ]
LOGIC_EXPR_L3 → [ EXPR_L1 < EXPR_L1 ]
LOGIC_EXPR_L3 → [ EXPR_L1 == EXPR_L1 ]
LOGIC_EXPR_L3 → [ EXPR_L1 != EXPR_L1 ]
NonTerminal(EXPR_L1):
EXPR_L1 → [ EXPR_L2 ]
EXPR_L1 → [ EXPR_L1 + EXPR_L2 ]
EXPR_L1 → [ EXPR_L1 - EXPR_L2 ]
NonTerminal(EXPR_L2):
EXPR_L2 → [ EXPR_L3 ]
EXPR_L2 → [ EXPR_L2 * EXPR_L3 ]
EXPR_L2 → [ EXPR_L2 / EXPR_L3 ]
NonTerminal(EXPR_L3):
EXPR_L3 → [ RHS ]
EXPR_L3 → [ ADDR_OF ]
EXPR_L3 → [ LITERAL ]
EXPR_L3 → [ - EXPR_L3 ]
EXPR_L3 → [ ( EXPR_L1 ) ]
EXPR_L3 → [ CALL ]
NonTerminal(TYPE):
TYPE → [ ARRAY ]
TYPE → [ POINTER ]
TYPE → [ struct identifier ]
TYPE → [ int ]
TYPE → [ byte ]
NonTerminal(ARRAY):
ARRAY → [ TYPE [ number_literal ] ]
NonTerminal(POINTER):
POINTER → [ TYPE * ]
NonTerminal(REF):
REF → [ identifier ]
REF → [ REF . identifier ]
REF → [ REF [ EXPR_L1 ] ]
NonTerminal(DEREF):
DEREF → [ * REF ]
DEREF → [ * DEREF ]
NonTerminal(ADDR_OF):
ADDR_OF → [ & REF ]
ADDR_OF → [ & string_literal ]
NonTerminal(RHS):
RHS → [ DEREF ]
RHS → [ REF ]
NonTerminal(LHS):
LHS → [ DEREF ]
LHS → [ REF ]
NonTerminal(LITERAL):
LITERAL → [ byte_literal ]
LITERAL → [ number_literal ]
LITERAL → [ string_literal ]
NonTerminal(IF):
IF → [ if LOGIC_EXPR_L1 BLOCK ]
IF → [ if LOGIC_EXPR_L1 BLOCK ELIF ]
IF → [ if LOGIC_EXPR_L1 BLOCK ELSE ]
NonTerminal(ELIF):
ELIF → [ elif LOGIC_EXPR_L1 BLOCK ]
ELIF → [ elif LOGIC_EXPR_L1 BLOCK ELIF ]
ELIF → [ elif LOGIC_EXPR_L1 BLOCK ELSE ]
NonTerminal(ELSE):
ELSE → [ else BLOCK ]
NonTerminal(LOOP):
LOOP → [ loop BLOCK ]