Esempio n. 1
0
        // 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");
        }
Esempio n. 2
0
        // 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");
 }
Esempio n. 5
0
 // 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());
     }
 }
Esempio n. 6
0
 // Recognize and translate an other
 private void Other()
 {
     Cradle.EmitLn(Cradle.GetName().ToString());
 }
Esempio n. 7
0
 // Output routine
 private void Output()
 {
     Cradle.Match('!');
     Console.WriteLine(Table[Cradle.GetName() - 'A']);
 }