I have this program and I have made the changes. Now I am trying to implement the stack within my code and im confused. I need to push the environment_types onto the stack but I dont know how. Here is what I have
int X=0, Y=0, Z=0 ;
/* Evironment classes are setup in order to implement the actions of the stack*/
Environment_Type envMain = new Environment_Type();
Environment_Type envA = new Environment_Type();
Environment_Type envB = new Environment_Type();
Environment_Type envC = new Environment_Type();
Stack envStack = new Stack();
// create a fileScan Scanner for a file, Simple.txt
// create a fileScan Scanner for a file, Simple.txt
Scanner fileScan = new Scanner(new File("simple.txt"));
String inputString = "";
String commandString;
inputString = fileScan.next();
// System.out.println (inputString);
if (inputString.equals ("begin"))
{
System.out.println ("Parsing begin");
// check whether the fileScan has the next item (i.e., next line)
while (fileScan.hasNext()) // check if there is any data to read
{
inputString = fileScan.next();
System.out.println (inputString);
if (inputString.equals ("end;"))
{
System.out.println ("Parsing End; Program");
System.exit(0);
}
else if (inputString.equals ("invoke")) //***************
{
System.out.print ("Parsing invoke ");
commandString = fileScan.next ();
System.out.println ("The Command is: " + commandString);
if (commandString.equals ("A;"))
{
envStack.push(envA); // Push environment A
}
else if (commandString.equals ("B;"))
{
envStack.push(envB);//push environment B
}
else if (commandString.equals ("C;"))
{
envStack.push(envC);//push environment C
}
}
else if (inputString.equals ("increment"))
{
System.out.print ("Parsing increment ");
commandString = fileScan.next ();
System.out.println ("The Command is: " + commandString);
if (commandString.equals ("X;"))
{
X++;
}
else if (commandString.equals ("Y;"))
{
Y++;
}
else if (commandString.equals ("Z;"))
{
Z++;
}
}
else if (inputString.equals ("decrement"))
{
System.out.print ("Parsing decrement ");
commandString = fileScan.next ();
System.out.println ("The Command is: " + commandString);
if (commandString.equals ("X;"))
{
X--;
}
else if (commandString.equals ("Y;"))
{
Y--;
}
else if (commandString.equals ("Z;"))
{
Z--;
}
}
else if (inputString.equals ("output"))
{
System.out.print ("Parsing output ");
commandString = fileScan.next ();
System.out.println ("The Command is: " + commandString);
if (commandString.equals ("X;"))
{
System.out.println("Value of X: "+ X);
}
else if (commandString.equals ("Y;"))
{
System.out.println("Value of Y: "+ Y);
}
else if (commandString.equals ("Z;"))
{
System.out.println("Value of Z: "+ Z);
}
}
else if (inputString.equals ("stop_sub"))
{
System.out.print ("Parsing Stop_sub; ");
}
}
}
else //if information is not found in file then the program is false
System.out.println ("Bad program");
}
}