Skip to main contentCal State San Bernardino / [CNS] / [Comp Sci Dept] / [R J Botting] / [CSci320] [Search ]
[Schedule] [Syllabi] [Text] [Labs] [Projects] [Resources] [Grading] [Contact]
Sessions: [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20]
08.html (HTML) [08.txt(Text)] Mon Jan 29 16:33:39 PST 2007

Contents


    CS320/08 Expressions and Assignment Statements

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

      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 3 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