私は学校プロジェクトのためにC#でコンパイラーをやっています。どうすればいいのか不思議に思って止めることはできません。そのHaskellの。例えばHaskellでコンパイラを書くには? C#で私は多くの状態を使用しています
:あなたが、私は方法の非常に中央でjumpToTheEndのコードを挿入する方法を見ることができます
public override void generateCode(Compiler compiler)
{
int jumpToTheBeginningInstructionIndex = compiler.getIndexOfNextActionInCurrentFunction();
MachineInstructions.JMP jumpTotheBeginning = new MachineInstructions.JMP(jumpToTheBeginningInstructionIndex);
MachineInstructions.JMPF jumpToTheEnd = new MachineInstructions.JMPF();
booleanExpression.generateCode(compiler);
//I insert the jump to the end here:
compiler.addAction(jumpToTheEnd);
foreach(IAction action in this.thenActions)
{
action.generateCode(compiler);
}
compiler.addAction(jumpTotheBeginning);
//...But is here where I know where should it jump to:
jumpToTheEnd.whereToJump = compiler.getIndexOfNextActionInCurrentFunction();
}
、しかしまでではありません。
Whileループのための私のコード生成があります私がジャンプがジャンプする行を知っている終わり。幸いにも、私はそのジャンプへのポインタを保持し、メソッドの最後にwhereToJump属性を簡単に設定できます。
ハスケルではどうしますか? お勧めチュートリアル?
単純な方法の1つは、関数の構造化テーブルを作成し、それを順番に呼び出すことです(HOFを展開する)。 –
ここに興味のある読書がありますhttp://en.wikibooks.org/wiki/Write_Yourself_a_Scheme_in_48_Hours –
@PedroRodriguesこれはインターピターであり、質問の主題であるコードジェニック段階が欠けています – jozefg