// Parse and translate a for statement private void DoFor() { Cradle.Match('f'); string L1 = Label.NewLabel(); string L2 = Label.NewLabel(); char Name = Cradle.GetName(); Cradle.Match('='); Expression(); Cradle.EmitLn("SUBQ #1,D0"); Cradle.EmitLn("LEA " + Name + "(PC),A0"); Cradle.EmitLn("MOVE D0,(A0)"); Expression(); Cradle.EmitLn("MOVE D0,-(SP)"); Label.PostLabel(L1); Cradle.EmitLn("LEA " + Name + "(PC),A0"); Cradle.EmitLn("ADDQ #1,D0"); Cradle.EmitLn("MOVE D0,(A0)"); Cradle.EmitLn("CMP (SP),D0)"); Cradle.EmitLn("BGT " + L2); Block(L2); Cradle.Match('e'); Cradle.EmitLn("BRA " + L1); Label.PostLabel(L2); Cradle.EmitLn("ADDQ #2,SP"); }
// Parse and translate an assignment statement private void Assignment() { char Name = Cradle.GetName(); Cradle.Match('='); Table[Name - 'A'] = Expression(); }
// Parse and translate an assignment statement private void Assignment() { char name = Cradle.GetName(); Cradle.Match('='); BoolExpression(); Cradle.EmitLn("LEA " + name + "(PC),A0"); Cradle.EmitLn("MOVE D0,(A0)"); }
// Parse and translate an identity private void Ident() { char name = Cradle.GetName(); if (Cradle.Look == '(') { Cradle.Match('('); Expression(); Cradle.Match(')'); Cradle.EmitLn("BSR " + name); } else Cradle.EmitLn("MOVE " + name + "(PC),D0"); }
// Parse and translate a math factor private int Factor() { if (Cradle.Look == '(') { Cradle.Match('('); int value = Expression(); Cradle.Match(')'); return(value); } else if (Cradle.IsAlpha(Cradle.Look)) { return(Table[Cradle.GetName() - 'A']); } else { return(Cradle.GetNum()); } }
// Recognize and translate an other private void Other() { Cradle.EmitLn(Cradle.GetName().ToString()); }
// Output routine private void Output() { Cradle.Match('!'); Console.WriteLine(Table[Cradle.GetName() - 'A']); }