ARTICLE AD BOX
You’ve been recruited by the Robotics Division to develop a Command Interpreter for their prototype robot. This robot can perform complex tasks—but only if the instructions are syntactically perfect. Your job is to write a program in the language of your choice (or adapt parse.cc) that checks whether a user-submitted instruction follows one of the five approved syntactic patterns.
If the instruction is valid, the robot will execute it. If not, your program must diagnose the error, explaining which part of the syntax is broken and why the robot would misinterpret it.
Instruction Rules/Patterns Your robot understands only the following formats: 1️⃣ <Time> <Behaviour> <Object> e.g., "2seconds push block"
2️⃣ <Object> <Colour> <Behaviour> e.g., "car red lift"
3️⃣ <Weight> <Behaviour> e.g., "heavy pull"
4️⃣ <Time> <Direction> <Time> <Direction> e.g., "1second left 2seconds forward"
5️⃣ <Behaviour> <Sector> <Object> e.g., "touch top_left pen"
Words Used in the Instruction Category Words ------------------------------------------- Time 1second, 2seconds, 3seconds Behaviour touch, push, pull, lift Direction left, right, forward, backward Sector top_left, top_right, lower_left, lower_right Weight light, medium, heavy Object car, apple, pen, block Colour red, blue, green, silver
Examples of correct and incorrect instructions 1second lift block ✅ pull lower_left apple ✅ 3seconds right ❎ 2seconds right 1second left ✅ lift lift ❎ block pull ❎ Program Requirements Accept a user instruction as input (e.g., "push top_left pen"). Parse the instruction and match it against the five valid patterns. If valid: print "✅ Instruction is acceptable to the robot". If invalid: Print "Instruction rejected." Explain which part of the syntax is incorrect (e.g., "Expected a <Time> but found 'apple'"). Suggest a corrected version. Track how many valid vs invalid instructions were submitted in a session.
