Package info.s5d.assembly.compiler

Source Code of info.s5d.assembly.compiler.AssemblyScriptCompiler

package info.s5d.assembly.compiler;

import info.s5d.assembly.AssemblyScript;
import info.s5d.assembly.compiler.token.BasicTokenHandler;
import info.s5d.assembly.compiler.token.TokenHandler;
import info.s5d.assembly.instruction.Instruction;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;

/**
* Class to read a script from a file/string into an AssemblyScript.
*
* @author Chris
*/
public class AssemblyScriptCompiler
{
  public static AssemblyScript compile(Reader reader) throws IOException
  {
    return compile(reader, new BasicTokenHandler());
  }

  public static AssemblyScript compile(Reader reader, TokenHandler tokenhandler) throws IOException
  {
    AssemblyScript script = new AssemblyScript();
   
    //Read each line of the script
    BufferedReader bufferedreader = new BufferedReader(reader);
   
    String line;
    while ((line = bufferedreader.readLine()) != null) {
      String[] tokens = line.split("\\s"); //split by whitespace
      Instruction instruction = tokenhandler.getInstructionByToken(tokens[0]);
      instruction.readParametersFromTokens(tokens);
      script.push(instruction);
    }
   
    return script;
  }
}
TOP

Related Classes of info.s5d.assembly.compiler.AssemblyScriptCompiler

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.