Package fjord.compiler

Source Code of fjord.compiler.Compiler

package fjord.compiler;

import fjord.runtime.*;
import fjord.Value;
import fjord.ast.*;

import org.antlr.runtime.ANTLRStringStream;
import org.antlr.runtime.CharStream;
import org.antlr.runtime.CommonTokenStream;

public class Compiler {

  private final String klass;

  public Compiler(String klass) {
    this.klass = klass;
  }

  public ScriptFragment parse(String input) throws Exception {
    CharStream stream = new ANTLRStringStream(input);

    FsharpLexer lexer = new FsharpLexer(stream);

    CommonTokenStream tokens = new CommonTokenStream(lexer);

    FsharpParser parser = new FsharpParser(tokens);

    return parser.scriptFragment();
  }

  public Value codegen(final ValueDefn defn) {
    try {
      Codegen codegen = new Codegen(klass);
      defn.accept(codegen);
      return (Value) JiteClassLoader.INSTANCE.loadClass(klass).newInstance();
    } catch (Exception e) {
      return new Value() { public Object eval() { return null; } };
    }
  }
}
TOP

Related Classes of fjord.compiler.Compiler

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.