我正在构建一个伪代码转换器和编译器.它通过执行几个字符串操作将伪代码转换为代码,然后它使用CSharpCodeProvider类来编译它,最后它尝试运行它.
经过几次测试后,如果翻译/输出代码如下:
using System;
using System.Collections.Generic;
public class TranslatedProgram
{
public static void ReadLine(ref int destiny)
{
destiny = int.Parse(Console.ReadLine());
}
public static void InsertInStack(ref Stack<int> originalStack, int value)
{
Console.WriteLine("Inserting the value " + value + " to the stack.");
originalStack.Push(value);
foreach (int current in originalStack)
{
Console.WriteLine("|" + current);
}
Console.WriteLine("_______");
}
public static void Main()
{
int value = new int();
Stack<int> data = new Stack<int>();
ReadLine(ref value);
InsertInStack(ref data, value);
}
}
Run Code Online (Sandbox Code Playgroud)
当应用程序将此代码发送到CSharpCodeProvider时,它不会编译.在compilerResults中,我收到以下错误:"无法找到类型或命名空间名称'Stack'(您是否缺少using指令或程序集引用?)" (CS0246) …