001 /** 002 * @author paulk, Jul 21, 2002 003 */ 004 005 package toolbus.process; 006 007 import java.util.Stack; 008 import toolbus.AtomList; 009 import toolbus.State; 010 import toolbus.TBTermFactory; 011 import toolbus.environment.Environment; 012 import toolbus.exceptions.ToolBusException; 013 import toolbus.parsercup.PositionInformation; 014 import aterm.ATermList; 015 016 public class LetDefinition extends ProcessExpression{ 017 private final ATermList locals; 018 private final ProcessExpression PEinit; 019 private final ProcessExpression PE; 020 private Environment env; 021 022 public LetDefinition(ATermList locals, ProcessExpression PE, TBTermFactory tbfactory, PositionInformation posInfo){ 023 super(tbfactory, posInfo); 024 this.locals = locals; 025 PEinit = PE; 026 this.PE = PE; 027 } 028 029 protected ProcessExpression copy(){ 030 return new LetDefinition(locals, PEinit.copy(), tbfactory, getPosInfo()); 031 } 032 033 protected void computeFirst(){ 034 PE.computeFirst(); 035 } 036 037 protected void replaceFormals(Environment e) throws ToolBusException{ 038 env = e.copy(); 039 env.introduceVars(locals); 040 PE.replaceFormals(env); 041 // env.removeBindings(formals); 042 } 043 044 protected void compile(ProcessInstance P, Stack<String> calls, State follows) throws ToolBusException{ 045 // System.err.println("LetDef.compile: " + env); 046 env.introduceVars(locals); 047 PE.compile(P, calls, follows); 048 env.removeBindings(locals); 049 // System.err.println("LetDef resulting env: " + env); 050 } 051 052 public State getFirst(){ 053 return PE.getFirst(); 054 } 055 056 public State getFollow(){ 057 return PE.getFollow(); 058 } 059 060 public AtomList getAtoms(){ 061 return PE.getAtoms(); 062 } 063 064 public String toString(){ 065 return "LetDefinition(" + locals + ", " + PE + ")"; 066 } 067 }