public ITypeCheckType TypeCheck(ITypeEnvironment env)
        {
            Action<VarAccessEventArgs> onVarAccess = (args) => args.SetVarInstance(0);

            //TODO: Make it so no casting is needed
            ((Environment.TypeEnvironment)env).VarAccess += onVarAccess;

            if (!env.IsDeclared(Name))
            {
                env.ReportError(String.Format("Attempting to use 'sum' on a non-existing variable '{0}'." +
                    "'sum' can only be used on variables used in a repeat.",
                    Name), SourceStartPosition, SourceEndPosition);

                return new UnknownType();
            }

            ITypeCheckType type = env.GetDeclared(Name);

            if (!type.CompatibleWith(ExpressionUpperBound))
            {
                env.ReportError(String.Format("Sum not possible. Incompatible type: '{0}'. Only numeric types are supported.",
                    type), SourceStartPosition, SourceEndPosition);

                return ExpressionUpperBound;
            }

            //TODO: Make it so no casting is needed
            ((Environment.TypeEnvironment)env).VarAccess -= onVarAccess;

            return type;
        }
        public void TypeCheck(ITypeEnvironment env)
        {
            if (env.IsDeclared(gotoDeclareName))
            {
                env.ReportError("You already defined a gotoNextForm. You can only have 1 per form.",
                    SourceStartPosition, SourceEndPosition);

                return;
            }

            env.Declare(gotoDeclareName, null);
        }
        public ITypeCheckType TypeCheck(ITypeEnvironment env)
        {
            if (!env.IsDeclared(Name))
            {
                env.ReportError(String.Format("Undefined variable '{0}' used. Make sure the variable is defined.",
                    Name), SourceStartPosition, SourceEndPosition);

                return new UnknownType();
            }

            return env.GetDeclared(Name);
        }
        public override ITypeCheckType TypeCheck(ITypeEnvironment env)
        {
            ITypeCheckType a = Expr1.TypeCheck(env);
            ITypeCheckType b = Expr2.TypeCheck(env);

            if (!a.CompatibleWith(ExpressionUpperBound) || !a.CompatibleWith(b))
            {
                env.ReportError(String.Format("Comparison using '>=' not possible. Incompatible types: '{0}', '{1}'. Only numeric types are supported.",
                    a, b), SourceStartPosition, SourceEndPosition);
            }

            return new BoolType();
        }
        public override ITypeCheckType TypeCheck(ITypeEnvironment env)
        {
            ITypeCheckType a = Expr1.TypeCheck(env);
            ITypeCheckType b = Expr2.TypeCheck(env);

            if (!a.CompatibleWith(ExpressionUpperBound) || !a.CompatibleWith(b))
            {
                env.ReportError(String.Format("'||' not possible. Incompatible types: '{0}', '{1}'. Only the bool type is supported.",
                    a, b), SourceStartPosition, SourceEndPosition);

                return ExpressionUpperBound;
            }

            return a.GetLeastUpperBound(b);
        }
        public FrameworkElement BuildForm(IValueEnvironment vEnv, ITypeEnvironment tEnv)
        {
            Button b = new Button() { Width = 200, Content = "Next" };

            b.Click += (s, e) =>
            {
                for (FrameworkElement fe = (FrameworkElement)b.Parent; fe != null; fe = (FrameworkElement)fe.Parent)
                {
                    if (fe is Selector)
                    {
                        ((Selector)fe).SelectedIndex++;
                        break;
                    }
                }
            };

            return b;
        }
 public IFormType BuildForm(ITypeEnvironment env)
 {
     return new RealType();
 }
 public IFormType BuildForm(ITypeEnvironment env)
 {
     return env.GetDeclared(Name);
 }
 public IFormType BuildForm(ITypeEnvironment env)
 {
     return ((Environment.TypeEnvironment)env).GetRange(Name).First();
 }