public static boolean parse(StringBuffer pattern, GElementTMOperation gop) { TMOperation op = gop.getOperation(); String s = pattern.toString(); if (s.startsWith(TMOperation.OPS_LEFT_UNTIL)) { pattern.delete(0, 2); gop.setLabel(TMOperation.OPS_LEFT_UNTIL + pattern.charAt(0)); op.setOperation(TMOperation.OP_LEFT_UNTIL); op.setParameter(pattern.substring(0, 1)); pattern.deleteCharAt(0); } else if (s.startsWith(TMOperation.OPS_LEFT_UNTIL_NOT)) { pattern.delete(0, 2); gop.setLabel(TMOperation.OPS_LEFT_UNTIL_NOT + pattern.charAt(0)); op.setOperation(TMOperation.OP_LEFT_UNTIL_NOT); op.setParameter(pattern.substring(0, 1)); pattern.deleteCharAt(0); } else if (s.startsWith(TMOperation.OPS_LEFT)) { pattern.deleteCharAt(0); gop.setLabel(TMOperation.OPS_LEFT); op.setOperation(TMOperation.OP_LEFT); } else if (s.startsWith(TMOperation.OPS_RIGHT_UNTIL)) { pattern.delete(0, 2); gop.setLabel(TMOperation.OPS_RIGHT_UNTIL + pattern.charAt(0)); op.setOperation(TMOperation.OP_RIGHT_UNTIL); op.setParameter(pattern.substring(0, 1)); pattern.deleteCharAt(0); } else if (s.startsWith(TMOperation.OPS_RIGHT_UNTIL_NOT)) { pattern.delete(0, 2); gop.setLabel(TMOperation.OPS_RIGHT_UNTIL_NOT + pattern.charAt(0)); op.setOperation(TMOperation.OP_RIGHT_UNTIL_NOT); op.setParameter(pattern.substring(0, 1)); pattern.deleteCharAt(0); } else if (s.startsWith(TMOperation.OPS_RIGHT)) { pattern.deleteCharAt(0); gop.setLabel(TMOperation.OPS_RIGHT); op.setOperation(TMOperation.OP_RIGHT); } else if (s.startsWith(TMOperation.OPS_OUTPUT)) { gop.setLabel(TMOperation.OPS_OUTPUT); op.setOperation(TMOperation.OP_OUTPUT); pattern.deleteCharAt(0); } else if (s.startsWith(TMOperation.OPS_YES)) { gop.setLabel(TMOperation.OPS_YES); op.setOperation(TMOperation.OP_YES); pattern.deleteCharAt(0); } else if (s.startsWith(TMOperation.OPS_NO)) { gop.setLabel(TMOperation.OPS_NO); op.setOperation(TMOperation.OP_NO); pattern.deleteCharAt(0); } else if (s.startsWith(TMOperation.OPS_CALL)) { pattern.deleteCharAt(0); // consume M pattern.deleteCharAt(0); // consume [ String machineName = pattern.substring(0, pattern.indexOf("]")); pattern.delete(0, pattern.indexOf("]") + 1); op.setOperation(TMOperation.OP_CALL); op.setParameter(machineName); gop.setLabel(TMOperation.OP_CALL + "[" + op.getParameter() + "]"); } else { op.setOperation(TMOperation.OP_WRITE); if (s.startsWith(TMMachine.SYMBOL_VAR)) { op.setParameter(pattern.substring(0, 2)); pattern.delete(0, 2); } else { op.setParameter(pattern.substring(0, 1)); pattern.deleteCharAt(0); } gop.setLabel(op.getParameter()); } return true; }
public static GElementTMOperation parse(StringBuffer pattern) { TMOperation op = new TMOperation(); GElementTMOperation gop = new GElementTMOperation(); gop.setOperation(op); return parse(pattern, gop) ? gop : null; }