diff --git a/src/main/java/de/tudresden/inf/st/mg/RobotParser.java b/src/main/java/de/tudresden/inf/st/mg/RobotParser.java index b21339f2ff102ecd5f97a691cf9146bed6f473e4..088fae7b1e878af3a80d459640fc65fcb669c7c4 100644 --- a/src/main/java/de/tudresden/inf/st/mg/RobotParser.java +++ b/src/main/java/de/tudresden/inf/st/mg/RobotParser.java @@ -27,7 +27,7 @@ public final class RobotParser extends MotionGrammarParser<Tidy> { while (true) { peekObjectAtWrongPlace(); if (peekedObjectAtWrongPlace_ != null) { - parseObjectAtWrongPlace(result.getMoveObjectToCorrectPlaceList(), result.getNumMoveObjectToCorrectPlace()); + parseMoveObjectToCorrectPlace(result.getMoveObjectToCorrectPlaceList(), result.getNumMoveObjectToCorrectPlace()); } else { break; } @@ -41,6 +41,84 @@ public final class RobotParser extends MotionGrammarParser<Tidy> { printAST("parseTidy", result); } + private void parseMoveObjectToCorrectPlace(ASTNode<?> parent, int index) throws ParseException { + MoveObjectToCorrectPlace result = (MoveObjectToCorrectPlace) parent.getChild(index); + + parseObjectAtWrongPlace(result, 0); + parsePickUpObject(result, 1); + parseDropObjectAtRightPlace(result, 2); + + // semantic action for T1 + result.action(getWorld()); + printAST("parseMoveObjectToCorrectPlace", result); + } + + private void parseDropObjectAtRightPlace(ASTNode<?> parent, int index) throws ParseException { + DropObjectAtRightPlace result = (DropObjectAtRightPlace) parent.getChild(index); + + parseRightPlace(result, 0); + parseDrop(result, 1); + + // semantic action for T1 + result.action(getWorld()); + printAST("parseDropObjectAtRightPlace", result); + } + + + private void parsePickUpObject(ASTNode<?> parent, int index) throws ParseException { + PickUpObject result = (PickUpObject) parent.getChild(index); + + parseRobotIsReadyToPick(result, 0); + parsePick(result, 1); + + // semantic action for T1 + result.action(getWorld()); + printAST("parsePickUpObject", result); + } + + private void parseRobotIsReadyToPick(ASTNode<?> parent, int index) throws ParseException { + RobotIsReadyToPick result; + + // try to parse a T + if (peekRobotIsFree()) { + result = new RobotIsReallyReadyToPick(); + parent.setChild(result, index); + parseRobotIsReallyReadyToPick(parent, index); + } else if (peekRobotIsBusy()) { + result = new RobotIsNotReadyToPick(); + parent.setChild(result, index); + parseRobotIsNotReadyToPick(parent, index); + } else { + throw new ParseException("RobotIsReadyToPick", RobotIsFree.type(), RobotIsBusy.type()); + } + + // semantic action for T1 + result.action(getWorld()); + printAST("parsePickUpObject", result); + } + + private void parseRobotIsReallyReadyToPick(ASTNode<?> parent, int index) throws ParseException { + RobotIsReallyReadyToPick result = (RobotIsReallyReadyToPick) parent.getChild(index); + + parseRobotIsFree(result, 0); + + // semantic action for T1 + result.action(getWorld()); + printAST("parseRobotIsReallyReadyToPick", result); + } + + private void parseRobotIsNotReadyToPick(ASTNode<?> parent, int index) throws ParseException { + RobotIsNotReadyToPick result = (RobotIsNotReadyToPick) parent.getChild(index); + + parseRobotIsBusy(result, 0); + parseWait(result, 1); + parseRobotIsReadyToPick(result, 2); + + // semantic action for T1 + result.action(getWorld()); + printAST("parseRobotIsNotReadyToPick", result); + } + private boolean peekObjectAtWrongPlace() { peekedObjectAtWrongPlace_ = getWorld().parseObjectAtWrongPlace(); return peekedObjectAtWrongPlace_ != null;