Source program Analysis of the LCC compiler (to) do and loop statements

Source: Internet
Author: User
The Do-while statement is a loop structure that implements the "until type". The general form is as follows: do {  Statement 1}while (expression)   The above statement is executed, EXECUTE statement 1 First, then determine the value of the expression, if the value of the expression is true, that is nonzero, return to execute statement 1, so repeatedly, until the value of the expression and so on Until 0. The difference between this expression and the previous while statement is the judgment of the expression value and the question that the statement 1 executes successively. The preceding while statement executes statement 1 first, and the Do-while statement is executed before judgment. The process of this statement is implemented in the LCC using the following function dostmt. #018   case do:       #019           Dostmt (Genlabel (3), SWP, Lev + 1); #020          expect (';'); #021          break;   The code for the DOSTMT function is as follows: #001  static void dostmt (int lab, swtch SWP, int lev) #002  {#003   refinc *= 1 0.0; #004   t = Gettok (); #005   definelab (Lab); #006   statement (Lab, SWP, Lev); #007   definelab (Lab + 1); #008   expect (while); #009   expect (' ('); #010   definept (NULL); #011   walk (Conditional (') '), lab, 0); #012   if (Findlabel (Lab + 2)->REF) #013          Definelab (Lab + 2); #014  } The 4th line is to get the next tick. Line 5th is the definition of the first label. Line 6th is the processing of statements in Do-while. Line 7th is the definition of the second label. The 8th line is to test if the while exists. The 11th line handles the conditional expression, and if the condition does not equal 0 it jumps to the first label there for processing. The 12th line is to see if you need to generate a third label, mainly in the loop to jump out of the statement prepared.   generates the following code form: Marking 1: Statement 1 Marking 2: If the conditional expression does not equal 0, jump to Marking 1Run Marking 3: The difference between it and the while loop is that the first jump instruction is less generated.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.