• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Virtual Machine or a Stack Processor

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 1093
29
Netbeans IDE Oracle MySQL Database Tomcat Server C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1093
29
Netbeans IDE Oracle MySQL Database Tomcat Server C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1093
29
Netbeans IDE Oracle MySQL Database Tomcat Server C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

This is what I added to my VirtualMachine
 
Slynn Garrett
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1093
29
Netbeans IDE Oracle MySQL Database Tomcat Server C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Slynn Garrett wrote:
This is what I added to my VirtualMachine

 
reply
    Bookmark Topic Watch Topic
  • New Topic