Package info.s5d.assembly.compiler.token

Source Code of info.s5d.assembly.compiler.token.TokenHandler

package info.s5d.assembly.compiler.token;

import info.s5d.assembly.instruction.Instruction;
import info.s5d.assembly.instruction.Instruction.Opcode;

import java.util.HashMap;

public class TokenHandler
{
  private HashMap<String, Opcode> tokenToOpcode = new HashMap<String, Opcode>();
  private HashMap<Opcode, String> opcodeToToken = new HashMap<Opcode, String>();
 
  protected void addToken(String token, Opcode opcode)
  {
    if (!tokenToOpcode.containsKey(token))
      tokenToOpcode.put(token, opcode);

    if (!opcodeToToken.containsKey(opcode))
      opcodeToToken.put(opcode, token);
  }
 
  public Opcode getOpcodeByToken(String token)
  {
    return tokenToOpcode.get(token);
  }

  public String getTokenByOpcode(Opcode opcode)
  {
    return opcodeToToken.get(opcode);
  }
 
  public Instruction getInstructionByToken(String token)
  {
    Opcode opcode = getOpcodeByToken(token);
    if (opcode == null)
      return null;
   
    return Instruction.getInstructionByOpcode(opcode);
  }
}
TOP

Related Classes of info.s5d.assembly.compiler.token.TokenHandler

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.