Skip to content

Commit 04a4b90

Browse files
authored
Merge pull request #6 from IagoMendes/v2.2
fixed parser
2 parents a942e4e + dbf40aa commit 04a4b90

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

Diff for: Classes/parser.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,29 @@
33

44
class Parser:
55
tokens = None
6+
count = 0
67

78
@staticmethod
89
def run(code):
910
Parser.tokens = Tokenizer(code)
1011
Parser.tokens.selectNext()
1112

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")
1319

1420
@staticmethod
1521
def parseBlock():
1622
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+
1927
stat.children.append(Parser.parseCommand())
20-
28+
2129
return stat
2230

2331
@staticmethod
@@ -124,7 +132,7 @@ def parseCommand():
124132

125133
else:
126134
raise NameError(f"Unexpected token {Parser.tokens.actual.type}")
127-
135+
128136
return result
129137

130138
@staticmethod

0 commit comments

Comments
 (0)