Please enable JavaScript.
Coggle requires JavaScript to display documents.
Language Design Principles Part 2 - Coggle Diagram
Language
Design Principles Part 2
Expression and Assignment
Statement
Expressions are the fundamental means of specifying
computations in a programming languages
Arithmetic
Expressions
The purpose of an arithmetic expression is to specify an
arithmetic computation
Parentheses
Operators
Binary
Ternary
Unary
Function calls
Operands
Order of evaluation
Important to know in order to avoid the
mistakes in executing the expressions
Precedence:
Define the order in which the operators of different precedence levels are evaluated based on the hierarchy of operator priorities.
Associativity:
When an expression contains 2 adjacent occurrences of operators with the same level of precedence, the question of which operator is evaluated first is answered by the associativity rules of the language
Parentheses:
A parenthesized part of an expression has precedence over its adjacent un-parenthesized parts
Used by programmers to alter the precedence & associativity rules by placing parentheses in expressions
Type Conversion
Narrowing Conversion
fractional part after the decimal point will
be lost
Disadvantage: potentially losing
information
Converts a value to a type that cannot store even approximations of all the values of the original type
Widening Conversion
Converts a value to a type that can include at least approximations of all the values of the original type
Advantage: it is safe, as there is no value
change (no information loss)
Relational & Boolean Expressions
Relational expressions:
A relational expression has 2
operands & one relational
operator
It returns a Boolean value
based on the comparison
A relational operator is an
operator that compares the
values of its 2 operands
Assignment Statement
Assignment statement provides the mechanism by which the user can dynamically change the bindings of values to variables.
Unary assignment
++ for increment
-- for decrement
Compound assignment
A compound assignment operator is a shorthand method of specifying a commonly needed form of assignment
Assignment as expressions
Mixed-mode Assignment
If the two input expressions are of different data types, the
expression is said to be a mixed mode expression.
The data type which appears furthest down in the table will be the
data type of the combined expression.
Binary operators combine two expressions into a single expression.
Statement-
level Control Structure
Selection statements
Provides the means of choosing between multiple possible execution paths
Can be categorized into 2 general categories:
Two-way selection – if ... else
Multiple selection -
switch
Iterative statements
An iterative statement is one that causes a statement or collection of statements to be executed zero, one or more times
2 styles can be applied to write an iterative statement: pre-test & post-test
Counter-controlled loops (Counting)
Logic-controlled loops (Logical)
A mixed controlled loops (Combination of both)
Flag – controlled loops
Compound statements/ Sequential Structure
Always written within delimiters such as begin/end pair or brackets.
A collection of statements & executed in sequential order that is
from the beginning (first statement) to the end (last statement).
Subprogram
A collection of statements that can be executed from multiple points within a program.
Procedures :
Collections of statements that
define parameterized
computations
Example: void methods
Functions:
Functions structurally resemble
procedures but are semantically
modeled on mathematical functions
Return value
Vocabulary
A subprogram call is an explicit request that the subprogram be
executed
A subprogram header is the first part of the definition, including the name, the kind of subprogram, and the formal parameters
A subprogram definition describes the interface to and the actions of the subprogram abstraction
The parameter profile (aka signature) of a subprogram is the number, order, and types of its parameters
The protocol is a subprogram’s parameter profile and, if it is a function, its return type
A subprogram declaration provides the protocol, but not the body, of the subprogram
Function declarations in C and C++ are often called prototypes
A formal parameter is a dummy variable listed in the subprogram header and used in the subprogram
An actual parameter represents a value or address used in the
subprogram call statement
Parameter Passing Methods
Pass-by-value-result - when an argument provides both input to, and output from the called function.
Pass-by-reference - same as pass-by-value- result
Pass-by-result - when an argument provides an output variable to which the called function can assign a result.
Pass-by-name - the expression in the call is not evaluated until it is used by the function
Pass-by-value - when an argument provides an input value to the called function.