예제 #1
0
파일: typecheck.cs 프로젝트: ydunk/masters
 void CheckInt(Exp e)
 {
     if (e.ExpType != typeof(int))
     {
         if (e is VarExp && e.ExpType == typeof(void))         //Param Variable. Type unknown. Assume first occurence
         {
             e.ExpType = typeof(int);
             CurrentFuncDef.Add(((VarExp)e).Name, typeof(int));
         }
         else if (e is DoVarExp && e.ExpType == typeof(void))    //Do Variable. Type unknown. Assume first occurence
         {
             e.ExpType = typeof(int);
             DoVars.Add(((DoVarExp)e).Pos, typeof(int));
         }
         else if (e is CallExp && e.ExpType == typeof(void))        //Recursive function call. Assume first occurence
         {
             e.ExpType = typeof(int);
         }
         else if (!(e is CarExp))                                   //CarExp will be coerceto int
         {
             Console.WriteLine("Int expected");
             success = false;
         }
     }
 }
예제 #2
0
파일: typecheck.cs 프로젝트: ydunk/masters
    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;
            }
        }
    }
예제 #3
0
파일: typecheck.cs 프로젝트: ydunk/masters
    public void DoVarDef(DoVarDef e)
    {
        e.Init.Visit(this);
        if (e.Init.ExpType != typeof(void))           //If type of init is known put it in.
        {
            if (DoVars[e.Pos] == null)
            {
                DoVars.Add(e.Pos, e.Init.ExpType);          //Else DoVarExp will add typeof(void)
            }
        }

        e.Iter.Visit(this);
        if (e.Init.ExpType == typeof(void) && e.Init is VarExp)  //If e.Init is VarExp which currently has no type.
        {
            e.Init.ExpType = (Type)DoVars[e.Pos];                //Assign it since now we know the type required.
            CurrentFuncDef.Add(((VarExp)e.Init).Name, e.Init.ExpType);
        }

        if (e.Init.ExpType != e.Iter.ExpType)
        {
            Console.WriteLine("Do Expression: Init and Iterations have different type");
            success = false;
        }
    }