CS362 2011F Compilers

Class 36: Translating Conditionals (2)

Back to Translating Conditionals (1). On to Translating Loops.

This outline is also available in PDF.

Held: Wednesday, 23 November 2011

Summary: We continue our exploration of the translation of conditional statements.

Related Pages:

Notes:

  • Translating with Short-Circuit Evaluation.

  • Short-Circuit Evaluation with Bison.

  • Translating Case Statements.

  • Translating Short-Circuit Conditionals

    Short-Circuit Evaluation in Yacc/Bison

    if_then_else
      : _IF 
        {
          translating_boolean = 1;  // Global flag
          Label *consequent_label = gen_label ();
          Label *alternate_label = gen_label ();
          push_label (consequent_label);
          push_label (alternate_label);
        }
      exp _THEN 
        {
          generate_instruction (_LABEL, consequent_label, NULL, NULL);
        }
      statement ELSE 
        {
          generate_instruction (_LABEL, alternate_label, NULL, NULL);
        }
      statement
        {
          AttributeSet *attributes = new_attribute_set (0);
          $$ = new_internal_node (_if_then_else, attributes, 3, $3, $6, $9);
        }
    

    Translating Case Statements

    Back to Translating Conditionals (1). On to Translating Loops.

    Disclaimer: I usually create these pages on the fly, which means that I rarely proofread them and they may contain bad grammar and incorrect details. It also means that I tend to update them regularly (see the history for more details). Feel free to contact me with any suggestions for changes.

    This document was generated by Siteweaver on Wed Dec 7 10:26:36 2011.
    The source to the document was last modified on Fri Aug 26 13:03:12 2011.
    This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS362/2011F/Outlines/outline.36.html.

    Samuel A. Rebelsky, rebelsky@grinnell.edu