001 /**
002 * Process operators
003 */
004 package toolbus.process;
005
006 import java.util.Stack;
007 import toolbus.AtomList;
008 import toolbus.State;
009 import toolbus.StateElement;
010 import toolbus.TBTermFactory;
011 import toolbus.environment.Environment;
012 import toolbus.exceptions.ToolBusException;
013 import toolbus.parsercup.PositionInformation;
014
015 /**
016 * ProcesssExpression represents abstract syntax operators for operators in process expressions of
017 * Tscripts. Specific operators like Sequence and Alternative are subclasses of ProcessExpression.
018 */
019 abstract public class ProcessExpression{
020 /**
021 * The term factory to be used.
022 */
023 protected final TBTermFactory tbfactory;
024
025 /**
026 * The first (entry) state for the automaton that implements this process expression.
027 */
028 private State first;
029
030 /**
031 * The state that follows (= connected to the exit of) the automaton that implements this
032 * process expression.
033 */
034 private State follow;
035
036 /**
037 * Position information (i.e., source code location) of this process expression.
038 */
039 protected final PositionInformation posInfo;
040
041 public ProcessExpression(TBTermFactory tbfactory, PositionInformation posInfo){
042 this.tbfactory = tbfactory;
043 this.posInfo = posInfo;
044
045 first = new State();
046 }
047
048 public State getFirst(){
049 return first;
050 }
051
052 protected void setFirst(State first){
053 this.first = first;
054 }
055
056 public PositionInformation getPosInfo(){
057 return posInfo;
058 }
059
060 protected void addToFirst(StateElement a){
061 first.addElement(a);
062 }
063
064 public State getFollow(){
065 return follow;
066 }
067
068 protected void setFollow(State follow){
069 this.follow = follow;
070 }
071
072 protected void addToFollow(State set){
073 follow = follow.union(set);
074 }
075
076 abstract protected void computeFirst();
077
078 abstract protected void replaceFormals(Environment env) throws ToolBusException;
079
080 abstract protected void compile(ProcessInstance processInstance, Stack<String> calls, State followSet) throws ToolBusException;
081
082 abstract protected ProcessExpression copy();
083
084 abstract public AtomList getAtoms();
085 }