示例#1
0
        /// <summary>
        /// Interprets the supplied befungeCode and returns the output as a string
        /// </summary>
        /// <returns>
        /// Returns the output of the supplied code
        /// </returns>
        /// <example>
        /// <code>
        /// string theOutput = BefungeInterpreter.Interpret(">321...@");
        /// </code>
        /// <code>
        /// string theOutput = BefungeInterpreter.Interpret(">321...@", Console.Out);
        /// </code>
        /// </example>
        /// <param name="befungeCode">A String containing befunge code.</param>
        /// <param name="outputStream">An optional TextWriter. It can be used to output to a file.</param>
        /// <param name="inputStream">An optional TextReader. It can be used to pass input from a file or the console.</param>
        public static string Interpret(string befungeCode, TextWriter outputStream = null, TextReader inputStream = null)
        {
            IMode           mode    = NumberMode.Instance;
            IBefungeRunTime runTime = new BefungeRunTime(befungeCode, mode, outputStream, inputStream);

            while (!runTime.EndProgram)
            {
                runTime.ExecuteInstruction();
            }

            return(runTime.Output);
        }
示例#2
0
 public BefungeRuntime_Should()
 {
     _textReaderMock = new Mock <TextReader>();
     _textWriterMock = new Mock <TextWriter>();
     _runtime        = new BefungeRunTime(_befungeCode, NumberMode.Instance, _textWriterMock.Object, _textReaderMock.Object);
 }