Enhance RobotLang grammar and visitor to support student ID extraction

This commit is contained in:
bobbert committed 2026-04-27 16:09:28 +01:00
1 parent 3fc4eac47b
commit 936f807449
4 files changed
+34 -16

No files matched your search

+6 -10
View File
@@ -9,22 +9,18 @@ def main(argv):
if len(argv) == 1:
inpstream = StdinStream()
else:
inpname = argv[9]
inpname = argv[1]
inpstream = FileStream(inpname)
# 1. Lexer analyses the characters
# Lexer analyses the characters
lexer = RobotLangLexer(inpstream)
# 2. Create a stream of tokens
# Create a stream of tokens
tokstream = CommonTokenStream(lexer)
# 3. Parser produces the abstract syntax tree
# Parser produces the abstract syntax tree
parser = RobotLangParser(tokstream)
# 4. Start parsing from the top rule ('prog' in your grammar)
# Start parsing from the top rule
tree = parser.prog()
# Printing the parse tree using Marina's PrettyPrint and toStringTree methods (Not-needed for the assignment)
# print(TreesUser.toStringTree(tree, None, parser))
# print(TreesUser.PrettyPrint(tree, None, parser))
visitor = RobotLangVisitorUser("2320390")
visitor = RobotLangVisitorUser()
visitor.visit(tree)
if __name__ == '__main__':