001 package toolbus.process; 002 003 import java.util.Iterator; 004 import java.util.Stack; 005 import toolbus.AtomList; 006 import toolbus.State; 007 import toolbus.TBTermFactory; 008 import toolbus.atom.Atom; 009 import toolbus.environment.Environment; 010 import toolbus.exceptions.ToolBusException; 011 import toolbus.parsercup.PositionInformation; 012 013 /** 014 * Disrupt is the abstract syntax operator for the disrupt operator (>>) in Tscripts. It is compiled 015 * away and does not exist during execution. 016 */ 017 public class Disrupt extends ProcessExpression{ 018 private ProcessExpression left; 019 private ProcessExpression right; 020 021 public Disrupt(ProcessExpression left, ProcessExpression right, TBTermFactory tbfactory, PositionInformation posInfo){ 022 super(tbfactory, posInfo); 023 this.left = left; 024 this.right = right; 025 } 026 027 protected ProcessExpression copy(){ 028 return new Disrupt(left, right, tbfactory, getPosInfo()); 029 } 030 031 protected void computeFirst(){ 032 left.computeFirst(); 033 right.computeFirst(); 034 setFirst(left.getFirst().union(right.getFirst())); 035 } 036 037 protected void replaceFormals(Environment env) throws ToolBusException{ 038 left.replaceFormals(env); 039 right.replaceFormals(env); 040 } 041 042 protected void compile(ProcessInstance P, Stack<String> calls, State follow) throws ToolBusException{ 043 left.compile(P, calls, follow); 044 right.compile(P, calls, follow); 045 State rightFirst = right.getFirst(); 046 setFollow(follow); 047 048 Iterator<Atom> atomSetIterator = left.getAtoms().iterator(); 049 while(atomSetIterator.hasNext()){ 050 Atom at = atomSetIterator.next(); 051 052 if(at.getFollow().size() != 0){ 053 at.addToFollow(rightFirst); 054 } 055 } 056 } 057 058 public AtomList getAtoms(){ 059 return left.getAtoms().union(right.getAtoms()); 060 } 061 }