Note that there are some explanatory texts on larger screens.

plurals
  1. POSmalltalk - Can write the Java program in Smalltalk?
    primarykey
    data
    text
    <p>I am trying to convert this Java interpreter I wrote for my compiler to a Smalltalk interpreter. Is it possible? If so, what would be a good resources to look at? I am completely new to Smalltalk, looks weird to me for now. I would appreciate any help, thanks. Some more info on the program: The input would be an intermediate code file a sample of which is as below.</p> <p>Intermediate code file, which computes the factorial of a number:</p> <pre><code>read store x push x store i push 1.0 store fact push i push 1.0 greater testfgoto 21 push fact push i multiply store fact push i push 1.0 minus store i push 1.0 testtgoto 7 push fact print end </code></pre> <p>JavaExecutor.java Program :</p> <pre><code>public void executor(){ String operation = null; StringTokenizer tokens = null; String key,value = null; Double tempVar = null; // Traverse the Arraylist to get the operations for(int i=0; i &lt; operations.size(); i++){ operation = (String)operations.get(i); System.out.println("Operation -------"+ operation); tokens = new StringTokenizer(operation); while(tokens.hasMoreTokens()){ key = tokens.nextToken(); //System.out.println("KEY "+ key); if(key.toUpperCase().equals("PUSH")){ //System.out.println("Push Operation"); value = (String)tokens.nextToken(); //System.out.println("value "+ value); if(checkforVaribaleName(value)){ stack.push((Double)assignments.get(value)); System.out.println("PUSH"+ (Double)assignments.get(value)); } else if(value != null){ stack.push(Double.parseDouble(value)); System.out.println("PUSH" + value); } else{ stack.push(0.0); System.out.println("PUSH" + 0.0); } break; }else if(key.toUpperCase().equals("POP")){ //NO LOGIC break; }else if(key.toUpperCase().equals("READ")){ //System.out.println("Read Operation"); tempVar = readDoubleFromConsole(); stack.push(tempVar); System.out.println("PUSHP :"+tempVar); break; }else if(key.toUpperCase().equals("WRITE")){ break; }else if(key.toUpperCase().equals("MULTIPLY")){ //System.out.println("MULTIPLY operation"); Double first = (Double)stack.pop(); Double second = (Double)stack.pop(); stack.push(first*second); System.out.println("PUSH "+ first*second); break; }else if(key.toUpperCase().equals("DIVIDE")){ Double first = (Double)stack.pop(); Double second = (Double)stack.pop(); stack.push(second/first); break; }else if(key.toUpperCase().equals("PLUS")){ Double first = (Double)stack.pop(); Double second = (Double)stack.pop(); stack.push(second+first); break; }else if(key.toUpperCase().equals("MINUS")){ Double first = (Double)stack.pop(); Double second = (Double)stack.pop(); stack.push(second-first); System.out.println("PUSH "+ (second-first)); break; }else if(key.toUpperCase().equals("GREATER")){ //System.out.println("GREATER operation"); Double first = (Double)stack.pop(); System.out.println("POP :"+first); Double second = (Double)stack.pop(); System.out.println("POP "+ second); if(second&gt;first){ stack.push(1.0); } else{ stack.push(0.0); } break; }else if(key.toUpperCase().equals("LESS")){ Double first = (Double)stack.pop(); Double second = (Double)stack.pop(); if(second&lt;first){ stack.push(1.0); } else{ stack.push(0.0); } break; }else if(key.toUpperCase().equals("EQUAL")){ Double first = (Double)stack.pop(); Double second = (Double)stack.pop(); if(second==first){ stack.push(1.0); } else{ stack.push(0.0); } break; }else if(key.toUpperCase().equals("STORE")){ //System.out.println("Store operation"); value = (String)tokens.nextToken(); assignments.put(value, (Double)stack.pop()); System.out.println("POP :"+assignments.get(value)); break; }else if(key.toUpperCase().equals("TESTFGOTO")){ value = (String)tokens.nextToken(); if((Double)stack.pop() == 0.0){ System.out.println("POP " +0.0); i = Integer.parseInt(value)-2; } break; }else if(key.toUpperCase().equals("TESTTGOTO")){ value = (String)tokens.nextToken(); if((Double)stack.pop() == 1.0){ System.out.println("POP " +1.0); i = (Integer.parseInt(value)-2); System.out.println(i); } break; }else if(key.toUpperCase().equals("PRINT")){ //System.out.println("PRINT operation"); System.out.println("Result "+stack.pop()); break; }else if(key.toUpperCase().equals("END")){ System.out.println("Execution Completed"); System.exit(0); } } } } public static void main(String args[]) { String fileName = null; if(args.length &gt; 0) { fileName = args[0]; } else{ System.out.println("Usage : JavaExecutor fileName.inp"); System.exit(0); } JavaExecutor j = new JavaExecutor(fileName); j.readFromFile(); j.executor(); } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload