Exemplo n.º 1
0
        public static CatList MakeUnit(Object x)
        {
            CatList result = new CatList();

            result.Add(x);
            return(result);
        }
Exemplo n.º 2
0
        public static CatList MakePair(Object first, Object second)
        {
            CatList result = new CatList();

            result.Add(first);
            result.Add(second);
            return(result);
        }
Exemplo n.º 3
0
        public CatList ToArray()
        {
            CatList[] a = new CatList[mDict.Count];
            int       i = 0;

            foreach (KeyValuePair <Object, Object> pair in mDict)
            {
                a[i++] = CatList.MakePair(pair.Value, pair.Key);
            }
            return(new CatList(a));
        }
Exemplo n.º 4
0
        public bool TestFunction(Function f)
        {
            bool bRet = true;

            testCount += 1;
            CatMetaDataBlock md = f.GetMetaData();

            if (md != null)
            {
                List <CatMetaData> tests = md.FindAll("test");
                foreach (CatMetaData test in tests)
                {
                    CatMetaData input  = test.Find("in");
                    CatMetaData output = test.Find("out");
                    if (input == null || output == null)
                    {
                        Output.WriteLine("ill-formed test in " + f.GetName());
                        return(false);
                    }
                    try
                    {
                        Executor aux = new Executor(this);
                        aux.Execute(input.GetContent());
                        CatList listInput = aux.GetStackAsList();
                        aux.Clear();
                        aux.Execute(output.GetContent());
                        CatList listOutput = aux.GetStackAsList();
                        aux.Clear();

                        if (!listInput.Equals(listOutput))
                        {
                            Output.WriteLine("failed test for instruction " + f.GetName());
                            Output.WriteLine("test input program = " + input.GetContent());
                            Output.WriteLine("test output program = " + output.GetContent());
                            Output.WriteLine("input program result = " + listInput.ToString());
                            Output.WriteLine("output program result = " + listOutput.ToString());
                            bRet = false;
                        }
                    }
                    catch (Exception e)
                    {
                        Output.WriteLine("failed test for instruction " + f.GetName());
                        Output.WriteLine("exception occured: " + e.Message);
                        bRet = false;
                    }
                }
            }
            return(bRet);
        }
Exemplo n.º 5
0
        public CatList ToList()
        {
            CatList ret = new CatList();

            ret.Add(GetLabel());
            if (Count > 0)
            {
                foreach (CatMetaData child in this)
                {
                    ret.Add(child);
                }
            }
            else
            {
                ret.Add(GetContent());
            }
            return(ret);
        }
Exemplo n.º 6
0
        public override bool Equals(object obj)
        {
            if (!(obj is CatList))
            {
                return(false);
            }
            CatList x = obj as CatList;

            if (Count != x.Count)
            {
                return(false);
            }
            for (int i = 0; i < Count; ++i)
            {
                if (!this[i].Equals(x[i]))
                {
                    return(false);
                }
            }

            return(true);
        }