public static void ParseLoop() { ParseNextLexem(); CodeGens.AddLabel(); string TopLabel = CodeGens.GetCurrentLabel(); CodeGens.AddLabel(); string LowLabel = CodeGens.GetCurrentLabel(); CodeGens.AddLabel(); string Thirdlabel = CodeGens.GetCurrentLabel(); currentLabel = Thirdlabel; CodeGens.AddInstructions("jmp " + LowLabel); CodeGens.AddInstructions(TopLabel + ":"); //ParseExpression(); ParseInstructionsSequence(); // CheckSyntax(Lexems.While); ParseNextLexem(); CodeGens.AddInstructions(LowLabel + ":"); ParseExpression(); CodeGens.AddInstructions("jmp " + TopLabel); CodeGens.AddInstructions(Thirdlabel + ":"); //{ // ParseNextLexem(); // CodeGens.AddLabel(); // string label = CodeGens.GetCurrentLabel(); // CodeGens.AddInstructions(label + ":"); // ParseInstructionsSequence(); // CheckLexems(Lexems.While); // ParseExpression(); //} }
public static void ParseBranching() { // //CheckLexems(Lexems.If); // ParseNextLexem(); // ParseExpression(); // CodeGens.AddLabel(); // string lowlable=CodeGens.GetCurrentLabel(); // currentLabel=lowlable; // CheckLexems(Lexems.Then); // ParseInstructionsSequence(); // while (currentLexem == Lexems.ElseIf) // { // ParseExpression(); // CheckLexems(Lexems.Then); // ParseInstructionsSequence(); // } // if (currentLexem == Lexems.Else) // { // ParseNextLexem(); // ParseInstructionsSequence(); // } // CheckLexems(Lexems.EndIf); ParseNextLexem(); CodeGens.AddLabel(); string lowestLabel = CodeGens.GetCurrentLabel(); currentLabel = lowestLabel; CodeGens.AddLabel(); string exitLabel = CodeGens.GetCurrentLabel(); ParseExpression(); CheckSyntax(Lexems.Then); ParseInstructionsSequence(); CodeGens.AddInstructions("jmp " + exitLabel); while (currentLexem == Lexems.ElseIf) { CodeGens.AddInstructions(lowestLabel + ":"); CodeGens.AddLabel(); lowestLabel = CodeGens.GetCurrentLabel(); currentLabel = lowestLabel; ParseNextLexem(); ParseExpression(); CheckSyntax(Lexems.Then); ParseInstructionsSequence(); CodeGens.AddInstructions("jmp " + exitLabel); } if (currentLexem == Lexems.Else) { CodeGens.AddInstructions(lowestLabel + ":"); // ParseNextLexem(); ParseInstructionsSequence(); } CheckSyntax(Lexems.EndIf); CodeGens.AddInstructions(exitLabel + ":"); }