学校编译原理专题实验,要将一个C#写的编译器自己看懂,然户再自己用另外一种语言实现,我只有对VC++6.0比较熟悉。现在做到一半做不下去了,一个星期光做这个都没做出来,谁有时间帮我看看啊。
编译器分为四个实现部分:词法分析、语法分析、符号表生成和中间代码生成。我已经做了词法分析,语法分析老是出错。
我把所有的东西放到邮箱了
[email protected] password:nigjtsky860626
如果与任何问题请发邮件[email protected]
谢谢各位了。
编译器分为四个实现部分:词法分析、语法分析、符号表生成和中间代码生成。我已经做了词法分析,语法分析老是出错。
我把所有的东西放到邮箱了
[email protected] password:nigjtsky860626
如果与任何问题请发邮件[email protected]
谢谢各位了。
String^ sourceFile,
String^ exeFile )
{ CompilerParameters^ cp = gcnew CompilerParameters;
if ( !cp)
{
return false;
} // Generate an executable instead of
// a class library.
cp->GenerateExecutable = true;
// Set the assembly file name to generate.
cp->OutputAssembly = exeFile;
// Generate debug information.
cp->IncludeDebugInformation = true;
// Add an assembly reference.
cp->ReferencedAssemblies->Add( "System.dll" );
// Save the assembly as a physical file.
cp->GenerateInMemory = false;
// Set the level at which the compiler
// should start displaying warnings.
cp->WarningLevel = 3;
// Set whether to treat all warnings as errors.
cp->TreatWarningsAsErrors = false;
// Set compiler argument to optimize output.
cp->CompilerOptions = "/optimize";
// Set a temporary files collection.
// The TempFileCollection stores the temporary files
// generated during a build in the current directory,
// and does not delete them after compilation.
cp->TempFiles = gcnew TempFileCollection( ".",true ); if ( provider->Supports( GeneratorSupport::EntryPointMethod ) )
{
// Specify the class that contains
// the main method of the executable.
cp->MainClass = "Samples.Class1";
} if ( provider->Supports( GeneratorSupport::Resources ) )
{
// Set the embedded resource file of the assembly.
// This is useful for culture-neutral resources,
// or default (fallback) resources.
cp->EmbeddedResources->Add( "Default.resources" );
// Set the linked resource reference files of the assembly.
// These resources are included in separate assembly files,
// typically localized for a specific language and culture.
cp->LinkedResources->Add( "nb-no.resources" );
} // Invoke compilation.
CompilerResults^ cr = provider->CompileAssemblyFromFile( cp, sourceFile ); if ( cr->Errors->Count > 0 )
{
// Display compilation errors.
Console::WriteLine( "Errors building {0} into {1}",
sourceFile, cr->PathToAssembly );
for each ( CompilerError^ ce in cr->Errors )
{
Console::WriteLine( " {0}", ce->ToString() );
Console::WriteLine();
}
}
else
{
Console::WriteLine( "Source {0} built into {1} successfully.",
sourceFile, cr->PathToAssembly );
} // Return the results of compilation.
if ( cr->Errors->Count > 0 )
{
return false;
}
else
{
return true;
}
}
http://blog.csdn.net/ctu_85/archive/2007/12/13/1932554.aspx
如果与任何问题请发邮件[email protected]
……
-----------------------
neverlandjj,好名字