File tree 1 file changed +13
-5
lines changed
1 file changed +13
-5
lines changed Original file line number Diff line number Diff line change 3
3
4
4
class Parser :
5
5
tokens = None
6
+ count = 0
6
7
7
8
@staticmethod
8
9
def run (code ):
9
10
Parser .tokens = Tokenizer (code )
10
11
Parser .tokens .selectNext ()
11
12
12
- return Parser .parseBlock ()
13
+ res = Parser .parseBlock ()
14
+
15
+ if (Parser .tokens .actual .type == "EOF" ):
16
+ return res
17
+ else :
18
+ raise NameError ("Expected EOF, please check your syntax" )
13
19
14
20
@staticmethod
15
21
def parseBlock ():
16
22
stat = Statement ()
17
- while (Parser .tokens .actual .type != "EOF" and Parser .tokens .actual .type != "END"
18
- and Parser .tokens .actual .type != "ELSE" and Parser .tokens .actual .type != "ELSEIF" ):
23
+
24
+ while (Parser .tokens .actual .type != "EOF" and Parser .tokens .actual .type != "END" and
25
+ Parser .tokens .actual .type != "ELSE" and Parser .tokens .actual .type != "ELSEIF" ):
26
+
19
27
stat .children .append (Parser .parseCommand ())
20
-
28
+
21
29
return stat
22
30
23
31
@staticmethod
@@ -124,7 +132,7 @@ def parseCommand():
124
132
125
133
else :
126
134
raise NameError (f"Unexpected token { Parser .tokens .actual .type } " )
127
-
135
+
128
136
return result
129
137
130
138
@staticmethod
You can’t perform that action at this time.
0 commit comments