Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Cat - A Statically Typed Programming Language Interpreter in C#

, 4 Nov 2006
This article contains the public domain implementation of an interpreter for a statically typed stack-based programming language in C# called Cat. The accompanying article is a high-level description of how the various modules work, a brief description of the language, and links to related work.
/// Public domain code by Christopher Diggins
/// http://www.cat-language.com

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Reflection;

namespace Cat
{
    /// <summary>
    /// By inheriting from this class, there are some utility functions
    /// which are provided and can be called using an unqualified name. 
    /// </summary>
    public class CatBase
    {
        public static void WriteLine(string s)
        {
            Console.WriteLine(s);
        }

        /// <summary>
        /// If the condition is false, an exception is thrown. This represents
        /// an internal error, such as a violated assumption. 
        /// </summary>
        public static void Assert(bool b, string s)
        {
            if (!b)
            {
                throw new Exception("internal error " + s);
            }
        }

        public static void Assert(bool b)
        {
            if (!b)
            {
                throw new Exception("internal error");
            }
        }

        public static void Log(string s)
        {
            WriteLine(s);
        }

        public static void Throw(string s)
        {
            throw new Exception(s);
        }

        public static bool AreObjectsEqual(Object x, Object y)
        {
            if (x == y) 
                return true;

            if (x is ArrayList)
            {
                if (!(y is ArrayList))
                    return false;
                ArrayList a = x as ArrayList;
                ArrayList b = y as ArrayList;
                if (a.Count != b.Count)
                {
                    return false;
                }
                else
                {
                    for (int i=0; i < a.Count; ++i)
                    {
                        if (!AreObjectsEqual(a[i], b[i]))
                            return false;
                    }
                    return true;
                }
            }
            else
            {
                return x.Equals(y);
            }
        }        
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Christopher Diggins
Software Developer Autodesk
Canada Canada
This article was written by Christopher Diggins, a computer science nerd who currently works at Autodesk as an SDK specialist.
Follow on   Twitter   Google+   LinkedIn

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141220.1 | Last Updated 4 Nov 2006
Article Copyright 2006 by Christopher Diggins
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid