示例#1
0
 protected void Prepare()
 {
     variables = new Variables();
     org = null;
     rofforCounter = 0;
     warriorName = null;
     authorName = null;
     variables["CORESIZE"] = new Value(project.Rules.CoreSize);
     variables["MAXPROCESSES"] = new Value(project.Rules.MaxProcesses);
     variables["MAXCYCLES"] = new Value(project.Rules.MaxCycles);
     variables["MAXLENGTH"] = new Value(project.Rules.MaxLength);
     variables["MINDISTANCE"] = new Value(project.Rules.MinDistance);
     variables["ROUNDS"] = new Value(project.Rules.Rounds);
     variables["PSPACESIZE"] = new Value(project.Rules.PSpaceSize);
     variables["VERSION"] = new Value(project.Rules.Version);
     variables["WARRIORS"] = new Value(project.Rules.WarriorsCount);
 }
示例#2
0
        private ExtendedWarrior Parse(string sourceText, string implicitName)
        {
            errCount = 0;
            Prepare();
            try
            {
                Statement statement = ParseInternal(sourceText);
                if (statement == null)
                    return null;
                ExtendedWarrior warrior = new ExtendedWarrior(project.Rules);
                int currentAddress;

                //first pass to expand for-rof cycles
                currentAddress = 0;
                variables["CURLINE"] = new Value(0);
                statement.ExpandStatements(warrior, this, ref currentAddress, project.Rules.CoreSize, false);
                SetRegisters();

                //second pass to evaluate variables/labels in context of for cycles
                currentAddress = 0;
                variables["CURLINE"] = new Value(0);
                statement.ExpandStatements(warrior, this, ref currentAddress, project.Rules.CoreSize, true);

                SetOrg(warrior);
                SetPin(warrior);
                SetName(warrior, implicitName);
                SetAuthor(warrior);
                Asserts(warrior);
                warrior.Variables = variables;
                if (errCount > 0)
                    return null;
                return warrior;
            }
            catch (ParserException)
            {
                return null;
            }
        }
示例#3
0
 private void SetRegisters()
 {
     for (char c = 'a'; c <= 'z';c++ )
     {
         string reg = c.ToString();
         if (!variables.ContainsKey(reg))
         {
             variables[reg] = new Value(0);
         }
     }
 }