All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.snapscript.tree.InstructionBuilder Maven / Gradle / Ivy

There is a newer version: 1.4.6
Show newest version
package org.snapscript.tree;

import java.util.HashMap;
import java.util.Map;

import org.snapscript.core.Context;
import org.snapscript.core.type.Type;
import org.snapscript.core.type.TypeLoader;

public class InstructionBuilder {
   
   private final InstructionReader reader;
   private final Context context;

   public InstructionBuilder(Context context, String file) {
      this.reader = new InstructionReader(file);
      this.context = context;
   }

   public Map create() throws Exception{
      Map table = new HashMap();   
      
      for(Instruction instruction : reader){
         Operation operation = create(instruction);
         String grammar = instruction.getName();
         
         table.put(grammar, operation);
      } 
      return table;
   }
   
   private Operation create(Instruction instruction) throws Exception{
      TypeLoader loader = context.getLoader();
      String value = instruction.getType();
      Type type = loader.loadType(value);
      String name = instruction.getName();
      
      return new Operation(type, name);
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy