Example #1
0
        public void visit(ConstantDeclaration that)
        {
            // resolve the type of the expression
            that.Expression.visit(this);

            // hack: fix up the likely incorrect type that the Parser created for the constant (always "Integer")
            switch (that.Expression.Type.Kind)
            {
            case TypeKind.Boolean:
                that.Type = new BooleanType(that.Expression.Position);
                break;

            case TypeKind.Integer:
                // simply keep the default integer type
                break;

            case TypeKind.String:
                that.Type = new StringType(that.Expression.Position);
                break;

            default:
                throw new CheckerError(that.Position, "Unknown type encountered: " + that.Expression.Type.Kind.ToString());
            }

            // nothing to check as we've just computed the type of the constant (cannot mismatch)

            if (!_symbols.Insert(that.Name, that))
            {
                throw new CheckerError(that.Position, "Duplicate name '" + that.Name + "' detected in constant declaration");
            }
        }