Esempio n. 1
0
        }                       // for serialization

        public Variable(string name, vartype type, int domain_start, int domain_end, DataGridViewCell c, string uName, int varIndexX, int varIndexY)
        {
            if (type == vartype.bool_type || type == vartype.string_type || type == vartype.float_type)
            {
                throw new ArgumentException("Domain specification only for int variables!");
            }

            this.type         = type;
            this.domain_start = domain_start;
            this.domain_end   = domain_end;
            this.name         = name;
            this.c            = c;

            this.uName       = uName;
            this.varIndexX   = varIndexX;
            this.varIndexY   = varIndexY;
            this.solvedValue = "";

            involvedInConstraint = new HashSet <Constraint>();

            this.locationX = c.ColumnIndex;
            this.locationY = c.RowIndex;

            sets = new HashSet <Set>();
        }
Esempio n. 2
0
        public Variable(string name, vartype type)
        {
            if (type == vartype.int_type)
            {
                throw new ArgumentException("Int variables must have a specific domain!");
            }

            this.type = type;
            this.name = name;
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Console.WriteLine("MLang Compiler version 0.1");
            Console.WriteLine("----Skye Sprung 2020----");
            if (args.Length < 1)
            {
                Console.WriteLine("Please pass a source file as argument 1");
                Environment.Exit(-1);
            }
            Console.WriteLine($"Attempting to load {args[0]}");
            try
            {
                src = File.OpenRead(args[0]);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            Console.WriteLine("Loaded successfully. Source code:");
            var lines = new List <string>(File.ReadLines(args[0]));

            foreach (var line in lines)
            {
                Console.WriteLine(line);
            }

            //--------------------------------------------
            //sources
            int indexOfSources = lines.IndexOf("Sources:");
            var sources        = lines.Where((string v, int i) => i > indexOfSources).ToList();

            Console.Write("attempting to parse variables from sources: ");
            foreach (string source in sources)
            {
                vartype temptype = vartype.Number;
                //determine type
                Regex book = new Regex("\"");
                if (book.IsMatch(source))
                {
                    temptype = vartype.Character;
                }
                string name = source.Split(",")[0];
                vars.Add(name, null);
                vartypes.Add(name, temptype);
            }
            Console.Write("Done.\n");

            //---------------------------------------------
            //parsing : preparation
            t = null;
            Console.WriteLine("Attempting to interpret.");
            Console.Write("\nOUTPUT::");
            var instructions = lines.Where((string s, int i) => i < indexOfSources).ToList();
            var inst         = new List <string>();

            foreach (var instruction in instructions)
            {
                Debug.WriteLine(instruction);
                var temp = instruction.Split(new char[] { '(', ')' });
                var odds = temp.Where((s, i) => i % 2 != 0);
                foreach (string odd in odds)
                {
                    inst.Add(odd);
                }
            }

            //parsing : parsing
            for (int i = 0; i < inst.Count; i++)
            {
                Debug.WriteLine($"parsing instruction {i}");
                string st = inst[i];
                Debug.WriteLine(st);
                var result = Interpret(st);
                switch (result.Item1)
                {
                case 0:
                    continue;

                case 1:
                    if (result.Item2 == null)
                    {
                        Console.WriteLine("\nNot enough arguments given in chapter reference, skipping.");
                    }
                    else
                    {
                        if (inst.Contains(result.Item2))
                        {
                            if (t != null)
                            {
                                if ((bool)t)
                                {
                                    i = inst.IndexOf(result.Item2);
                                }
                            }
                            else
                            {
                                Console.WriteLine("\nYou have not compared anything yet, please use \"Contrast\" before using \"read\"");
                                Environment.Exit(-1);
                            }
                        }
                        else
                        {
                            Console.WriteLine($"\nThis chapter ({result.Item2}) does not seem to exist.");
                        }
                    }
                    continue;
                }
            }
            Console.WriteLine("\nDone. Thank you for citing your sources!");
        }