Exemplo n.º 1
0
        public override Type Typecheck(TypecheckingState state)
        {
            Type = Expression.Typecheck(state);
            state.EnterScope();
            state.BindVariable(Name, Type);
            var type = Recipient.Typecheck(state);

            state.ExitScope();
            return(type);
        }
        // public string Name;
        // public string ArgumentName;
        // public Type ArgumentType;
        // public Type ReturnType;
        // public Expression Body;
        // public Expression Recipient;

        public override Type Typecheck(TypecheckingState state)
        {
            state.EnterScope();
            state.BindFunction(Name, this);

            // type check the body once
            state.EnterScope();
            state.BindVariable(ArgumentName, ArgumentType);
            var returnType = Body.Typecheck(state);

            if (returnType != ReturnType)
            {
                TypeError("Return type mismatch");
            }
            state.ExitScope();

            var type = Recipient.Typecheck(state);

            state.ExitScope();

            return(type);
        }