mirror of
https://github.com/mudabbir-ahmad/UNI-PROG3-CW2-DYOPL.git
synced 2026-10-07 20:00:20 +00:00
44 lines
1.2 KiB
Python
44 lines
1.2 KiB
Python
from RobotLangVisitor import RobotLangVisitor
|
|
|
|
class RobotLangVisitorUser(RobotLangVisitor):
|
|
def __init__(self):
|
|
self.student_id = "Unknown"
|
|
|
|
def visitHeader(self, ctx):
|
|
self.student_id = ctx.NUMBER().getText()
|
|
return self.visitChildren(ctx)
|
|
|
|
def visitMoveStat(self, ctx):
|
|
val = ctx.NUMBER().getText()
|
|
print(f"{self.student_id} is moving by {val}.")
|
|
return self.visitChildren(ctx)
|
|
|
|
def visitGrabStat(self, ctx):
|
|
print(f"{self.student_id} is grabbing.")
|
|
return self.visitChildren(ctx)
|
|
|
|
def visitReleaseStat(self, ctx):
|
|
print(f"{self.student_id} is releasing.")
|
|
return self.visitChildren(ctx)
|
|
|
|
def visitWaitStat(self, ctx):
|
|
val = ctx.NUMBER().getText()
|
|
print(f"{self.student_id} is waiting for {val}.")
|
|
return self.visitChildren(ctx)
|
|
|
|
def visitLogStat(self, ctx):
|
|
val = ctx.STRING().getText()[1:-1]
|
|
print(f"{self.student_id} is logging: {val}.")
|
|
return self.visitChildren(ctx)
|
|
|
|
def visitRepeatStat(self, ctx):
|
|
times = int(ctx.NUMBER().getText())
|
|
for _ in range(times):
|
|
for stat_ctx in ctx.stat():
|
|
self.visit(stat_ctx)
|
|
return None
|
|
|
|
|
|
|
|
|