Exemplo n.º 1
0
    public CodeGen(ExpList ex, Hashtable f, Hashtable g)
    {
	expr = ex;
	Functions = new Hashtable();
	GlobalVars = new Hashtable();
	DoVars = new Hashtable();
    }
Exemplo n.º 2
0
    public bool Parse()
    {
	//e = null;
	e = MatchStm();
	//	Match(TokenType.EoFSym);
	MatchToken(TokenType.EOFSYM);
	Tc = new TypeCheck(e, Functions);
	bool tsuccess = Tc.Check();
	e = Tc.e;                                       //Exp is modified in TypeCheck
	return success && tsuccess;                     //Return success if both parsing and typechecking succeed.
    }
Exemplo n.º 3
0
    ExpList MatchStm()
    {
	ExpList ex1 = new ExpList();
	ex1.Head = MatchExp();
	if(((Token)tokens.Peek()).Type != TokenType.EOFSYM){
	    ex1.Tail = MatchStm();
	}
	else 
	    ex1.Tail = null;

	return ex1;
    }
Exemplo n.º 4
0
    public TypeCheck(ExpList el, Hashtable f)
    {
	e = el;
	Functions = new Hashtable();

	ArrayList Params = new ArrayList();
	Params.Add(typeof(CList));
	Functions.Add("Cdr", new FunctionDef("Cdr", Params, null));
	Functions.Add("IsNull", new FunctionDef("IsNull", Params, null));
	Functions.Add("IsAtom", new FunctionDef("IsAtom", Params, null));
	
	Params.Add(typeof(CList));
	Functions.Add("Cons", new FunctionDef("Cons", Params, null));
	Params.Add(typeof(CList));
	Functions.Add("Subst", new FunctionDef("Subst", Params, null));

	GlobalVars = new Hashtable();
	success = true;
	CurrentFuncDef = null;
    }
Exemplo n.º 5
0
	public DoExp(ExpList v, ExpList c)
	{
	    Vars = v;
	    Conds = c;
	}
Exemplo n.º 6
0
    ExpList MatchDoCondList()
    {
	ExpList el1 = new ExpList();
	
	//MatchToken(TokenType.LPAREN);
	
	el1.Head = MatchDoCond();
	if(((Token)tokens.Peek()).Type != TokenType.RPAREN){
	    el1.Tail = MatchDoCondList();
	}
	else {
	    el1.Tail = null;
	}
	
	//MatchToken(TokenType.RPAREN);
	
	return el1;
	
    }
Exemplo n.º 7
0
    public void Generate(String filename)
    {
	AppDomain ad = Thread.GetDomain(); //AppDomain.CreateDomain("First", null, null);
	AssemblyName an = new AssemblyName();
    an.Name = filename + ".exe"; //AssemblyName.CreateSimpleName(filename + ".exe", "LispExe", "Lisp Executable", "default_alias");
	AssemblyBuilder ab = ad.DefineDynamicAssembly(an, AssemblyBuilderAccess.RunAndSave);
	ModuleBuilder mb = ab.DefineDynamicModule(filename + ".exe", filename + ".exe");
	MethodBuilder methodb;
	//DescriptorInfo di = new DescriptorInfo(0);
	tb = mb.DefineType(filename);
	
	//di.SetReturnType(typeof(void));
	//di.MethodAttributes = MethodAttributes.Static | MethodAttributes.Public;
	methodb = tb.DefineMethod("Main", MethodAttributes.Static | MethodAttributes.Public, typeof(void), null);
	il = methodb.GetILGenerator();

	do{
	    expr.Head.Visit(this);
    	    if (expr.Head is FunctionDef)
    		GenerateDefStub(((FunctionDef)expr.Head).Name);
     	    else if (expr.Head is GlobalVarDef)
    		GenerateDefStub(((GlobalVarDef)expr.Head).Name);
 	    else if (expr.Head.ExpType == typeof(int))
  		GenerateNumericExpStub();
    	    else if (expr.Head.ExpType == typeof(bool))
		GenerateBoolExpStub();
    	    else if (expr.Head.ExpType == typeof(CList)) 
    		GenerateListExpStub();
	    
	    expr = expr.Tail;
	}while(expr != null);
	
	il.Emit(OpCodes.Ret);
	tb.CreateType();
	
	ab.SetEntryPoint((mb.GetType(filename)).GetMethod("Main"));
	ab.Save(filename + ".exe");
    }
Exemplo n.º 8
0
    void CheckList(ref Exp e)
    {
	if (e.ExpType == typeof(int)){
	    e = new ToListExp(e);
	    e.ExpType = typeof(CList);
	}
	
	if (e.ExpType != typeof(CList)){
	    if (e is VarExp && e.ExpType == typeof(void)){
		e.ExpType = typeof(CList);
		CurrentFuncDef.Add(((VarExp)e).Name, typeof(CList));
	    }
	    else if (e is DoVarExp && e.ExpType == typeof(void)){
		e.ExpType = typeof(CList);
		DoVars.Add(((DoVarExp)e).Pos, typeof(CList));
	    }
	    else if (e is CallExp && e.ExpType == typeof(void)){       //Recursive function call. Assume first occurence
		e.ExpType = typeof(int);
	    }
	    else if (!(e is IntExp)){                                  //IntExp will be coerceto List
		Console.WriteLine("List expected");
		success = false;
	    }
	}
    }