-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAMMScript.py
More file actions
46 lines (34 loc) · 1.48 KB
/
AMMScript.py
File metadata and controls
46 lines (34 loc) · 1.48 KB
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
from antlr4 import *
import sys
from antlr.AMMScriptLexer import AMMScriptLexer
from antlr.AMMScriptParser import AMMScriptParser
from antlr4.error.ErrorListener import ErrorListener
from AMMScriptParserVisitor import AMMScriptParserVisitor
class MyErrorListener( ErrorListener ):
def __init__(self):
super(MyErrorListener, self).__init__()
def syntaxError(self, recognizer, offendingSymbol, line, column, msg, e):
raise Exception("Błąd składniowy w linii " + str(line) + " w kolumnie " + str(column))
'''
def reportAmbiguity(self, recognizer, dfa, startIndex, stopIndex, exact, ambigAlts, configs):
self.defaultError(startIndex, stopIndex, "Ambiguity")
def reportAttemptingFullContext(self, recognizer, dfa, startIndex, stopIndex, conflictingAlts, configs):
self.defaultError(startIndex, stopIndex, "Attempting full context")
def reportContextSensitivity(self, recognizer, dfa, startIndex, stopIndex, prediction, configs):
self.defaultError(startIndex, stopIndex, "Context sensitivity")
'''
def interpret(code):
lexer = AMMScriptLexer(InputStream(code))
stream = CommonTokenStream(lexer)
parser = AMMScriptParser(stream)
parser.removeErrorListeners()
parser.addErrorListener(MyErrorListener())
visitor = AMMScriptParserVisitor(parser)
try:
visitor.visit(parser.program())
except Exception as e:
print(e)
results = visitor.getResults()
results.append(str(e))
return results
return visitor.getResults()