[Skip Navigation] [CSUSB] / [CNS] / [Comp Sci & Eng] / [R J Botting] /[CS320 Course Materials] /08.html [08.txt(Text)] [Search ]
Thu Apr 8 19:19:34 PDT 2010
[Schedule] [Syllabi] [Text] [Labs] [Projects] [Resources] [Grading] [Contact]
Notes: [01] [02] [03] [04] [05] [06] [07] [08] [09] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20]

Contents


    CS320/08 Expressions and Assignment Statements


      Table
      Prev [ 07.html ] Data Types Chapter 6 lab07 C/C++ Data
      08Expressions etcChapter 7lab08 C/C++ Expressions
      Next [ 09.html ] Control structures Chapter 8 not section 5 lab09 C/C++ Control

      (Close Table)

      Preparation

      Study chapter 7. This chapter is about expressions and assignments. See the UML diagram.

      Expressions and Assignments

      Answer review questions on chapter 7.

      Hand in answers to 2 or more review questions.

      Note 1: Expressions are not Statements

      Be careful to distinguish Expressions from Statements. Expressions are evaluated and return Values. Statements are executed and return a new State. Most languages have both.

      Note 2: Precedence and Associativity

      You may want to express precedence and associativity in your project.

      These are syntax not semantics. Express precedence and associativity in BNF/EBNF/XBNF not in the UML. It takes some extra definitions. See sections 3.3.1.7, 3.3.1.8 and 3.3.1.9 in the book.

      For example, suppose we might define

    1. expression::= simple_expression #( operator simple_expression),
    2. operator::= "+" | "*".

      But this does not show the relative precedence of "+" and "*".

      We show the precedence of "*" and "+" in algebra by replacing the above by:

    3. expression::= term #( "+" term),
    4. term::= simple_expression #( "*" simple_expression).

      To express associativity we can replace the '#' by recursion. For example:

    5. expression::= term | expression "+" term, -- left associative.
    6. term::= simple_expression| simple_expression "*" term, -- right associative.

      Warning: it is unusual(and confusing) to have different associativities for multiplication and addition in a real language.

    Class Work

    [ 08q.html ]

    Lab Work

    [ lab/08.html ]

    Next

    [ 09.html ]

End