Esempio n. 1
0
        public string ValidateProgram([NotNull] string program)
        {
            var warriorParser = new MarsWarriorParser(rules);
            var warrior       = warriorParser.TryParse(program, string.Empty);

            return(warrior == null?warriorParser.GetErrorMessages() : null);
        }
        private ExtendedWarrior ParseWarrior([NotNull] ProgramStartInfo programStartInfo, [NotNull] string filename)
        {
            var warriorParser = new MarsWarriorParser(rules);
            var implicitName  = Path.GetFileNameWithoutExtension(filename);
            var warrior       = warriorParser.TryParse(programStartInfo.Program, implicitName);

            if (warrior == null)
            {
                throw new WarriorProgramParserException(string.Format("Failed to parse warrior {0} [{1}]: {2}", implicitName, warriorParser.GetErrorMessages(), programStartInfo));
            }
            warrior.FileName = filename;
            warrior.PredefinedLoadAddress = programStartInfo.StartAddress;
            return(warrior);
        }