PLC Session 5

The fifth Session of semester 1 is talking about Expression and Assignment Statements this Session will be presented by our friend’s group. As usual, this session divided into some topics that shown below

  • Introduction
  • Arithmetic Expressions
  • Overloaded Operators
  • Type Conversions
  • Relational and Boolean Expressions
  • Short-Circuit Evaluation
  • Assignment Statements
  • Mixed-Mode Assignment

Without further ado i will sum up what we discussed on that day. The first topic is about introduction as usual. It explain to us what are Expressions, Expressions are the fundamental means of specifying computations in a programming language. It is crucial for a programmer to understand both the syntax and semantics of expressions of the language being used.  In this fifth session, the semantics of expressions from session 2 are discussed.The essence of the imperative programming languages is the dominant role of assignment statements. The purpose of these statements is to cause the side effect of changing the values of variables, or the state, of the program. Move on to the next topic, we were discussing about Arithmetic Expressions,  In programming languages, arithmetic expressions consist of operators, operands, parentheses, and function calls. An operator can be unary, meaning it has a single operand, binary, meaning it has two operands, or ternary, meaning it has three operands. We also discussed about overloaded operators,  arithmetic operators are often used for more than one purpose. For example, + usually is used to specify integer addition and floating-point addition. Some languages—Java, for example—also use it for string catenation. This multiple use of an operator is called operator overloading and is generally thought to be acceptable, as long as neither readability nor reliability suffers. Next topic is about  type conversions

Type conversions are either narrowing or widening. A narrowing conversion converts a value to a type that cannot store even approximations of all of the values of the original type. For example, converting a double to a float in Java is a narrowing conversion, because the range of double is much larger than that of float. A widening conversion converts a value to a type that can include at least approximations of all of the values of the original type. For example, converting an int to a float in Java is a widening conversion. We learned that a number of errors can occur during expression evaluation. If the language requires type checking, either static or dynamic, then operand type errors cannot occur. Next topic is about Relational and Boolean Expressions. Let’s discuss what is relational expressions, A relational operator is an operator that compares the values of its two operands. A relational expression has two operands and one relational operator. The value of a relational expression is Boolean, except when Boolean is not a type included in the language. The relational operators are often overloaded for a variety of types. The syntax of the relational operators for equality and inequality differs among some programming languages. For example, for inequality, the C-based languages use !=, Ada uses /=, Lua uses ~=, Fortran 95+ uses .NE. or <>, and ML and F# use <>. JavaScript and PHP have two additional relational operators, === and !==. These are similar to their relatives, == and !=, but prevent their operands from being coerced. Next we talked about Boolean Expressions. Boolean expressions consist of Boolean variables, Boolean constants, relational expressions, and Boolean operators. The operators usually include those for the AND, OR, and NOT operations, and sometimes for exclusive OR and equivalence. Another topic is about Short-Circuit Evaluation. A short-circuit evaluation of an expression is one in which the result is determined without evaluating all of the operands and/or operators. For example, the value of the arithmetic expression

(13 * a) * (b / 13 – 1)

is independent of the value of (b / 13 – 1) if a is 0, because 0 * x = 0 for any x. So, when a is 0, there is no need to evaluate (b / 13 – 1) or perform the second multiplication. Move on to next topic is about Assignment Statements, Assignment Statements provides the mechanism by which the user can dynamically change the bindings of values to variables. ALGOL 60 pioneered the use of := as the assignment operator, which avoids the confusion of assignment with equality. Ada also uses this assignment operator. The design choices of how assignments are used in a language have varied widely. We also learned that a compound assignment operator is a shorthand method of specifying a  commonly needed form of assignment. Compound assignment operators were introduced by ALGOL 68, example of compound assignment is shown below

sum += value;

is equivalent to

sum = sum + value;

The last topic is about Mixed-Mode Assignment. One of the design decisions concerning arithmetic expressions is whether an operator can have operands of different types. Languages that allow such expressions are called mixed-mode expressions. All in all Expressions consist of constants, variables, parentheses, function calls, and operators. Assignment statements include target variables, assignment operators, and expressions.

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *