• Post Reply Bookmark Topic Watch Topic
  • New Topic

Virtual Machine or a Stack Processor  RSS feed

 
Slynn Garrett
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please bare with me here. I am new to java ranch and I am not sure how to word things.
I have a project that uses a translator and instruction class. My teacher corrected my classes (translation and instruction) to work the way she wants them too. I now have to create a virtual machine class that:
VirtualMachine should include the following basic functionality:
• Have instance data for
- A StackProcessor object
- Simulated memory object
• Use an Instruction collection created by the Translator
- Remove one Instruction at a time and cause it to be executed
- Use the StackProcessor to execute instructions of the appropriate operation codes
- Use a simulated implementation of memory to execute memory-related instructions
(STORE, RECALL, INPUT)
• Use console I/O

Here is my classes or Instruction and Translator

Here is how she suggest the Virtual Machine to look:
For example, your VirtualMachine class could look something like this:
public class VirtualMachine
{
private StackProcessor processor = new StackProcessor();
private [something to represent memory];

public void process (ArrayDeque<Instruction> instructions)
{

while (! instructions.isEmpty())
{
Instruction ins = instructions.remove();

while (ins.getOperationCode() != Instruction.OPCode.END)
{
switch (ins.getOperationCode())
{
case PUSH:
processor.push(ins.getValue());
break;

}
This is what I have so far for my Virtual Machine

What I am trying to figure out is where I am going wrong with Scanning for a file and then telling it what to do with the file.I think I am reading it but cant figure out how to read line by line for instructions. I AM STUCK
 
Les Morgan
Rancher
Posts: 779
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Here is a link to the Scanner API to give you what other features are available: http://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html
 
Slynn Garrett
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe I have to ask the user or a filename then see if it is there.... then call the classes.
 
Les Morgan
Rancher
Posts: 779
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read through the Scanner API in the link I gave you. The Scanner class will probably be your easiest way of getting input from a file or from the keyboard, the API has further examples that will help you, then if you have a specific question please ask it. Examples of how you are using, actual code, will help a lot in getting a more specific answer than what I have been able to give you from your questions thus far.

Sherry Kaiser wrote:I believe I have to ask the user or a filename then see if it is there.... then call the classes.
 
Slynn Garrett
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am doing that now as we speak. My teacher just informed me that we only need a Scanner for the VirtualMachine, but only for the instructions associated with memory - for input, you need to ask for the value to be input for the variable. Which confuses me even more.
 
Les Morgan
Rancher
Posts: 779
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are still going to have to prompt the user and collect console input from them when you ask for the variable? If so, then you will use another Scanner as described in the API docs.

Sherry Kaiser wrote:I am doing that now as we speak. My teacher just informed me that we only need a Scanner for the VirtualMachine, but only for the instructions associated with memory - for input, you need to ask for the value to be input for the variable. Which confuses me even more.
 
Slynn Garrett
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok I have the scanner accepting an integer. But how would I pass it to my other class?
I orgot to put my stackProcessor code in as well
 
Slynn Garrett
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This is what I added to my VirtualMachine
 
Slynn Garrett
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can not figure this out. I have the virtual machine scanning for a value. But I can not figure out how to get it to it into the translator class. Atleast I think it would go into the translator
 
Les Morgan
Rancher
Posts: 779
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Slynn Garrett wrote:
This is what I added to my VirtualMachine
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!