SlideShare a Scribd company logo
COMPILERS: PROGRAMMING
LANGUAGES
ASSIGNMENTS - STATEMENTS.
1
Presentation By: Geo S. Mariyan
(Master in Computer Science)
Assignment - Introduction
• Assignment is to "assign a pre declared variable with
some value or by the value of another variable of the
same data type. This is done anywhere in body of the
program.
For E.g. : n=9 or m=5 then, n=5 !
assigns value 5 to n
• Initialization is telling compiler to allocate a
memory to the initialized variable so that compiler can
know that this variable is going to store some value.
2
ASSIGNMENT – Symbolic Representation
• ASSIGNMENT: The Basic Operation for changing the binding of
the value to the data object.
• Assignment also returns the value, which is a data object
containing the copy of a value assigned.
3
Ex : int a; Initializing 'a' as of type int
Assignment means proving a particular value to
any variable.
Ex: int a=2; a in assigned a value to 2.
This is purely assignment and assignment
can be done n no. of times in a program. There is no
such restriction on it.
Assignment throws away the old value of a
variable and replacing it with a new one. It can be done
anywhere in the whole program.
4
l- and r- values
• An lvalue can appear on the left side of an assignment
operator, whereas an rvalue can appear on the right side.
• "lvalue" and "rvalue" are so named because of where each
of them can appear in an assignment operation.
• ex: int a, b;
• a = 4;
• b = a;
• In the third line of that example, "b" is the lvalue, and "a"
is the rvalue, whereas it was the lvalue in line.
• This illustrates an important point: An lvalue can also be
an rvalue.
5
Assignment Operators
• An assignment operator is the operator used
to assign a new value to a variable, property, event or
indexer element.
• Assignment operators can also be used for logical
operations such as bitwise logical operations or
operations on integral operands and Boolean operands.
• Unlike in C++, assignment operators in C# cannot be
overloaded directly, but the user-defined types can
overload the operators like +, -, /, etc. This allows the
assignment operator to be used with those types.
6
Characteristics of Assignment Operators:
• The different assignment operators are based on the type of
operation performed between two operands such as addition
(+=), subtraction, (-=), etc. The meaning of the operator
symbol used depends on the type of the operands.
• Assignment operators are right-associative, which means they
are grouped from right to left.
• Although assignment using assignment operator (a += b)
achieves the same result as that without ( =a +b), the
difference between the two ways is that unlike in the latter
example, "a" is evaluated only once.
7
Practice with Assignment Operators
The assignment operator expects the type of both
the left- and right-hand side to be the same for
successful assignment.
Example:
i += 24
i *= x
8
Variant forms of Assignment
•Augmented Assignment
•Chained Assignment
•Parallel Assignment
9
• Augmented assignment: The case where the assigned
value depends on a previous one is so common that many
imperative languages, most notably C and the majority of
its descendants, provide special operators
called Augmented assignment
ex: *=, so a = 2*a can instead be written as a *= 2
• Chained assignment: A statement like w = x = y = z is
called a chained assignment in which the value of z is
assigned to multiple variables w, x, and y. Chained
assignments are often used to initialize multiple variables, as
in
•example: a = b = c = d = f = 0
10
Parallel Assignment:
Some programming languages, such
as Go, JavaScript (since, Maple, Perl, Python, REBOL, Ruby,
and Windows Power Shell allow several variables to be
assigned in parallel, with syntax like:
ex: a, b := 0, 1
which simultaneously assigns 0 to a and 1 to b. This is most
often known as parallel assignment.
11
Assignment statements
• Once a variable is declared, it can be assigned values
multiple times in a program; for example:
int num; // num declared,
uninitialized
num = 3; // num assigned 3
num = num + 1; // num assigned 3 + 1 (4)
num = 15 / num; // num assigned 15 / 4
12
Implementation of Assignment:
• Compiler can implement the assignment A := B
• The Compiler generates code to compute the r-value and B
into some register r-value of B into some register r
• If the data types of A and B are incompatible, the compiler
generates code to convert the r-value of B to a type
appropriate for A.
• If necessary, the compiler generates the code to determine
the l-value of A.
(if A is in primitive type , no code is needed)
• Finally, the compiler generates code to store the
contents of register r into the l-values of A.
13
Assignment compatibility
• When a variable is declared, the data type in the
declaration indicates the nature of the values the variable is
capable of storing.
• For example, an int variable can store a whole number, a
char variable can store a character, and a double variable
can store a real number.
• The value assigned to the variable must be compatible with
its data type.
14
•Java is a strongly-typed language.
•This means that, for the most part, you can only
assign a value of a particular data type to a
variable of the same type
•Some examples:
int x = -2; // this is fine; -2 is an integer
char c = ‘2’; // this is OK also
x = 2.5; // syntax error: 2.5 is a double value,
not an int
c = 2; // also an error; 2 is an int value, not a
char
15
Assignment Statement Variety:
= FORTRAN, C, C++, Java
= Can be bad if it is overloaded for the
relational operator for equality.
• Example
C: a=b=c
• In the C statement A = B = C, the value of C is
assigned to B, and the value of B is assigned to A.
16
Statements:
Definition :
A statement in programming context is a
single complete programming instruction that is
written as code.
The Elementary action of evaluation,
assignment and control of evaluation orders are
specified by the statements of the programming
language .
Statements can have diverse forms and
languages.
17
Function Call Statement
•Certain function calls, such as the MESSAGE function,
can be a statement on their own. They are known as
function call statements
•
18
The Statement Separator
A single programming statement may span
several code lines; one code line may consist of
multiple statements.
Therefore, the C compiler must be able to
detect when one statement ends and another
statement begins.
[ <statement> { ; <statement> } ]
Example : Integer Num:=10;
19
Assignment Statement
In computer programming, an assignment
statement sets and/or re-sets the value stored in the
storage location(s) denoted by a variable name; in other
words, it copies a value into the variable. In most
imperative programming languages, the assignment
statement (or expression) is a fundamental construct.
The syntax of an assignment statement is almost as easy
as the syntax of the function call statement. The syntax is
as follows:
<variable> := <expression>
20
Assignment Statement
• Assignment statements can be in the following two forms
1) x := op y
2) x := y op z
• First statement op is a unary operation. Essential unary
operations are unary logical negation, shift operators and
conversion operators.
• Second statement op is a binary arithmetic or logical
operator.
21
Assignment Operator
• An assignment operator is the operator used
to assign a new value to a variable, property, event or
indexer element in C# programming language.
• Assignment operators can also be used for logical
operations such as bitwise logical operations or operations
on integral operands and Boolean operands.
• The “colon equals” (:=) is known as the assignment
operator. You use it to assign a value or an expression that
evaluates to a value to a variable.
• :=
22
Jump Statements
• The jump statements are the goto statement, the
continue statement, the break statement, and the
return statement.
• The source statement like if and while-do cause jump in the
control flow through three address code so any statement in
three address code can be given label to make it the target of a
jump.
23
Indexed Assignment
• Indexed assignment of the form A:=B[I] and A[I]:=B.
the first statement sets A to the value in the location I
memory units beyond location B.
• In the later statement A [I]:=B, sets the location I units
beyond A to the value of B.
• In Both instructions A, B, and I are assumed to refer
data objects and will represented by pointers to the
symbol table.
24
Address and Pointer Assignment
• Address and pointer assignment
x := &y
x := *y
*x := y
• First statement, sets the value of x to be
the location of y.
• In x := *y, here y is a pointer or
temporary whose r-value is a location. The r-value of
x is made equal to the contents of that location.
• *x := y sets the r-value of the object
pointed to by a to the r-value of y.
25
Assignment Operations
• Most basic statements for initializing variables
• General syntax:
• variable = expression;
• Example:
• length = 25;
• Expression
• Any combination of constants and variables that
can be evaluated to yield a result
26
•All variables used in an expression must
previously have been given valid values.
•Must be a variable listed immediately to the
left of the equal sign.
•Has lower precedence than any other
arithmetic operator.
27
Assignment Statements: Compound
Operators
•A shorthand method of specifying a
commonly needed form of assignment.
•Introduced in ALGOL; adopted by C
Example:
a = a + b is written as a += b
•Unary assignment operators in C-based
languages combine increment and decrement
operations with assignment.
28
Examples:
• sum = ++count (count incremented,
then assigned to sum)
• sum = count++ (count assigned to sum,
then incremented)
• count++ (count incremented)
• -count++ (count incremented then negated)
29
Assignment as an Expression
• In C, C++, and Java, the assignment statement
produces a result and can be used as operands
• An example:
while ((ch=getchar())!= EndOfFile){…}
ch = getchar() is carried out; the result
(assigned to ch) is used as a conditional value for the
while statement
30
Simple and Compound Statements
• Simple Statement: A Simple statement is one which
does not contain any augmented statement.
• Read, Assignment and goto are the three examples of
simple statements.
• In certain languages, a program may be regarded
as a sequence of simple statements. (e.g., BASIC,
SNOBOL)
• Compound Statement: A Compound Statement is one
that may contain one or more embedded statements.
• The logical IF in FORTRAN
• IF (condition) statement
31
Compound statements: The Compound Statement
enable computation that logically belong together and
be grouped together syntactically.
• This ability of grouping together helps make program
readable.
Example of Compound statement:
1. If condition then statement
2. If condition then statement else statement
3. While condition do statement
32
Explanation:
• The if-then and if-then-else statements allows all actions
that apply for the value of condition to be grouped
together.
• The compound statements permits the sequence of the
statements to be used wherever one may appear.
• The while statements is to establish the loops with
arbitrary loop control conditions.
• In compound statement in other languages the syntax
may be widely different.
•Note*: The test for the condition is performed
before the statements allowing the loops to be
executed zero times if necessary.
33
Types of Statements
1. Conditional Statements.
2. Sequential Statements.
3. Control Statements.
4.Structural Statements.
5. Declaration Statements.
6.Input Statements.
7. Output Statements.
34
Conditional Statements:
• In Conditional statements are features of
a programming language, which perform different
computations or actions depending on whether a
programmer specified boolean condition evaluates to true
or false.
35
36
Conditional statement is a set of rules
performed if a certain condition is met. Below are some
examples of conditional statements in programming.
this last example will print if it is greater than 10, less than 10
or equal to 10.
Sequential Statement:
• In most languages , control automatically flows from one
statement to the next.
• Certain statements such as goto, break, call and return
deliberately alter the flow of control.
• There has been considerable debate as to what statements
are best suited for creating easy to understand flow-of-
control patterns in programs.
• The Sequential statement has been the focus and it permits
the arbitrary flow-of-control patterns, including those that
are difficult to comprehend.
37
38
Example:
Control Structure:
• A control statement is a statement that determines whether
other statements will be executed.
• An if statement decides whether to execute
another statement, or decides which of two statements to
execute.
• A loop decides how many times to execute another statement.
• while loops test whether a condition is true before executing
the controlled statement.
• do-while loops test whether a condition is true after executing
controlled statement.
39
40
•The for loops are (typically) used to execute the controlled
statement a given number of times.
•A switch statement decides which of several statements to
execute.
Structural Statements:
• Certain Statements such as END serve to group Simple
statements into structures.
• Following the structured program theorem:
• "Sequence: Ordered statements or subroutines
executed in sequence.
• "Selection: One or a number of statements is
executed depending on the state of the program. This is
usually expressed with keywords such as if..then..else.
41
42
Iteration: a statement or block is executed until the program
reaches a certain state, or operations have been applied to
every element of a collection. This is usually expressed with
keywords such as while, repeat, for or do..until
Recursion: a statement is executed by repeatedly calling itself
until termination conditions are met.
Declaration Statements:
• These statements generally produce no executable
code.
• Their semantic effect is to uniform the compiler about
the attributes of names encountered in the program .
• The compiler implements’ a declaration statement by
storing the attribute information contained therein in
the symbol table and then consulting this information
whenever declared names are used in program.
43
44
•Declaration of a variable serves two purposes: It associates a
type and an identifier (or name) with the variable. The type
allows the compiler to interpret statements correctly.
•Declarations are most commonly used for functions, variables,
constants, and classes, but can also be used for other entities
such as enumerations and type definitions.
Input & Output Statements:
• These statements serve the role as their names .
• In many languages they are implemented by library subroutines
made available by operating system to control input/output
devices.
• It convert data to human readable form.
• In variety of languages we see formats, which are strings of
information about how data is to be interpreted or Expressed
(Read or Write)
45
46
Example:
47

More Related Content

What's hot (20)

PDF
Cs6503 theory of computation november december 2015 be cse anna university q...
appasami
 
PPTX
Sad considerations for-candidate_system
Swapnil Walde
 
PPTX
Arp and rarp
Nita Dalla
 
PPT
NFA or Non deterministic finite automata
deepinderbedi
 
PPTX
Back patching
santhiya thavanthi
 
PPTX
Knowledge representation and Predicate logic
Amey Kerkar
 
PPTX
Three address code In Compiler Design
Shine Raj
 
PDF
Difference b/w 8085 & 8086
j4jiet
 
PPT
Lecture 3,4
shah zeb
 
PPTX
Relationship Among Token, Lexeme & Pattern
Bharat Rathore
 
PPTX
Design of a two pass assembler
Dhananjaysinh Jhala
 
PPTX
System Programming- Unit I
Saranya1702
 
PDF
Theory of Computation Lecture Notes
FellowBuddy.com
 
PDF
Stack and subroutine
milandhara
 
PPT
Line drawing algo.
Mohd Arif
 
PPTX
Depth Buffer Method
Ummiya Mohammedi
 
PPTX
Two pass Assembler
Satyamevjayte Haxor
 
PPT
Backtracking Algorithm.ppt
SalmIbrahimIlyas
 
PPTX
Directed Acyclic Graph Representation of basic blocks
Mohammad Vaseem Akaram
 
PPTX
System Programing Unit 1
Manoj Patil
 
Cs6503 theory of computation november december 2015 be cse anna university q...
appasami
 
Sad considerations for-candidate_system
Swapnil Walde
 
Arp and rarp
Nita Dalla
 
NFA or Non deterministic finite automata
deepinderbedi
 
Back patching
santhiya thavanthi
 
Knowledge representation and Predicate logic
Amey Kerkar
 
Three address code In Compiler Design
Shine Raj
 
Difference b/w 8085 & 8086
j4jiet
 
Lecture 3,4
shah zeb
 
Relationship Among Token, Lexeme & Pattern
Bharat Rathore
 
Design of a two pass assembler
Dhananjaysinh Jhala
 
System Programming- Unit I
Saranya1702
 
Theory of Computation Lecture Notes
FellowBuddy.com
 
Stack and subroutine
milandhara
 
Line drawing algo.
Mohd Arif
 
Depth Buffer Method
Ummiya Mohammedi
 
Two pass Assembler
Satyamevjayte Haxor
 
Backtracking Algorithm.ppt
SalmIbrahimIlyas
 
Directed Acyclic Graph Representation of basic blocks
Mohammad Vaseem Akaram
 
System Programing Unit 1
Manoj Patil
 

Viewers also liked (20)

PPTX
Mobile security in Cyber Security
Geo Marian
 
PPTX
Presentation on visual basic 6 (vb6)
pbarasia
 
PPT
Introduction to visual basic programming
Roger Argarin
 
PDF
Developing functional safety systems with arm architecture solutions stroud
Arm
 
PPTX
Business intelligence
Geo Marian
 
PPTX
Visual Basic Controls ppt
Ranjuma Shubhangi
 
PPT
Visual basic ppt for tutorials computer
simran153
 
PPTX
Sledeshare. nurith pastran. procesal laboral
pastrannurith
 
PPT
Modern Compiler Design
nextlib
 
PPTX
RedHealthAsia 2015
scotthk
 
PPTX
Steps when designing a forecast process
Stefan Harrstedt
 
ODP
Wordpress Boilerplate Plugin Powered
Daniele Scasciafratte
 
PPTX
Office exercise
Engr. Carlo Senica, MBA, CPSM
 
PDF
ELK: a log management framework
Giovanni Bechis
 
PDF
2010: Mobile Security - Intense overview
Fabio Pietrosanti
 
PPTX
Introduction to ELK
YuHsuan Chen
 
PDF
Log analysis with the elk stack
Vikrant Chauhan
 
PPTX
compiler and their types
patchamounika7
 
PDF
ArcherGrey PLM Product Uploader NEW Dashboard & Mobile
Brion Carroll
 
PPTX
Elk with Openstack
Arun prasath
 
Mobile security in Cyber Security
Geo Marian
 
Presentation on visual basic 6 (vb6)
pbarasia
 
Introduction to visual basic programming
Roger Argarin
 
Developing functional safety systems with arm architecture solutions stroud
Arm
 
Business intelligence
Geo Marian
 
Visual Basic Controls ppt
Ranjuma Shubhangi
 
Visual basic ppt for tutorials computer
simran153
 
Sledeshare. nurith pastran. procesal laboral
pastrannurith
 
Modern Compiler Design
nextlib
 
RedHealthAsia 2015
scotthk
 
Steps when designing a forecast process
Stefan Harrstedt
 
Wordpress Boilerplate Plugin Powered
Daniele Scasciafratte
 
ELK: a log management framework
Giovanni Bechis
 
2010: Mobile Security - Intense overview
Fabio Pietrosanti
 
Introduction to ELK
YuHsuan Chen
 
Log analysis with the elk stack
Vikrant Chauhan
 
compiler and their types
patchamounika7
 
ArcherGrey PLM Product Uploader NEW Dashboard & Mobile
Brion Carroll
 
Elk with Openstack
Arun prasath
 
Ad

Similar to Compiler: Programming Language= Assignments and statements (20)

PPTX
comp 122 Chapter 2.pptx,language semantics
floraaluoch3
 
PPTX
ChapterTwoandThreefnfgncvdjhgjshgjdlahgjlhglj.pptx
berihun18
 
PPSX
Esoft Metro Campus - Programming with C++
Rasan Samarasinghe
 
PPTX
Operators in C Programming
Jasleen Kaur (Chandigarh University)
 
PPTX
C basics
sridevi5983
 
PPTX
C basics
sridevi5983
 
PPTX
TOKENS-grp-4[1].pptx PLLEASE DOWNLOAD IT
aluffssdd804
 
PPTX
C sharp part 001
Ralph Weber
 
PPT
M.Florence Dayana / Basics of C Language
Dr.Florence Dayana
 
PPTX
Unit 2- Control Structures in C programming.pptx
shilpar780389
 
PPTX
C programming
DipjualGiri1
 
PDF
2nd PUC Computer science chapter 5 review of c++
Aahwini Esware gowda
 
PPTX
Fundamentals of computers - C Programming
MSridhar18
 
PPT
Basic concept of c++
shashikant pabari
 
PPT
Intro Basics of C language Operators.ppt
SushJalai
 
PDF
Lec-2- Ehsjdjkck. Jdkdbd djskrogramming.pdf
RahulKumar342376
 
PPTX
Lecture 2 variables
Tony Apreku
 
PDF
Lamborghini Veneno Allegheri #2004@f**ck
seidounsemel
 
PPTX
ExpressionsInJavaScriptkkkkkkkkkkkkkkkkk
kamalsmail1
 
PDF
Unit ii chapter 1 operator and expressions in c
Sowmya Jyothi
 
comp 122 Chapter 2.pptx,language semantics
floraaluoch3
 
ChapterTwoandThreefnfgncvdjhgjshgjdlahgjlhglj.pptx
berihun18
 
Esoft Metro Campus - Programming with C++
Rasan Samarasinghe
 
Operators in C Programming
Jasleen Kaur (Chandigarh University)
 
C basics
sridevi5983
 
C basics
sridevi5983
 
TOKENS-grp-4[1].pptx PLLEASE DOWNLOAD IT
aluffssdd804
 
C sharp part 001
Ralph Weber
 
M.Florence Dayana / Basics of C Language
Dr.Florence Dayana
 
Unit 2- Control Structures in C programming.pptx
shilpar780389
 
C programming
DipjualGiri1
 
2nd PUC Computer science chapter 5 review of c++
Aahwini Esware gowda
 
Fundamentals of computers - C Programming
MSridhar18
 
Basic concept of c++
shashikant pabari
 
Intro Basics of C language Operators.ppt
SushJalai
 
Lec-2- Ehsjdjkck. Jdkdbd djskrogramming.pdf
RahulKumar342376
 
Lecture 2 variables
Tony Apreku
 
Lamborghini Veneno Allegheri #2004@f**ck
seidounsemel
 
ExpressionsInJavaScriptkkkkkkkkkkkkkkkkk
kamalsmail1
 
Unit ii chapter 1 operator and expressions in c
Sowmya Jyothi
 
Ad

Recently uploaded (20)

PPTX
Presentation for a short film .pptx.pptx
madisoncosta17
 
PPTX
677697609-States-Research-Questions-Final.pptx
francistiin8
 
PDF
FINAL ZAKROS - UNESCO SITE CANDICACY - PRESENTATION - September 2024
StavrosKefalas1
 
PPTX
Pastor Bob Stewart Acts 21 07 09 2025.pptx
FamilyWorshipCenterD
 
PDF
Medical Technology Corporation: Supply Chain Strategy
daretruong
 
PPTX
AI presentation for everyone in every fields
dodinhkhai1
 
PDF
CHALLENGIES FACING THEOLOGICAL EDUCATION IN NIGERIA: STRATEGIES FOR IMPROVEMENT
PREVAILERS THEOLOGICAL SCHOOL FCT ABUJA
 
PDF
Mining RACE Newsletter 10 - first half of 2025
Mining RACE
 
PPTX
Food_and_Drink_Bahasa_Inggris_Kelas_5.pptx
debbystevani36
 
PPTX
A brief History of counseling in Social Work.pptx
Josaya Injesi
 
PDF
From 0 to Gemini: a Workshop created by GDG Firenze
gdgflorence
 
PPTX
English_Book_2 part 2 let reviewers news
2022mimiacadserver
 
PPTX
BARRIERS TO EFFECTIVE COMMUNICATION.pptx
shraddham25
 
PDF
Buy Old GitHub Accounts -Trusted Sellers
GitHub Account
 
PPTX
Blended Family Future, the Mayflower and You
UCG NWA
 
PPTX
Presentationexpressions You are student leader and have just come from a stud...
BENSTARBEATZ
 
PPTX
2025-07-13 Abraham 07 (shared slides).pptx
Dale Wells
 
PPTX
Bob Stewart Humble Obedience 07-13-2025.pptx
FamilyWorshipCenterD
 
PPTX
English_Book_1 part 1 LET Reviewers NEw-
2022mimiacadserver
 
PPT
Wireless Communications Course lecture1.ppt
abdullahyaqot2015
 
Presentation for a short film .pptx.pptx
madisoncosta17
 
677697609-States-Research-Questions-Final.pptx
francistiin8
 
FINAL ZAKROS - UNESCO SITE CANDICACY - PRESENTATION - September 2024
StavrosKefalas1
 
Pastor Bob Stewart Acts 21 07 09 2025.pptx
FamilyWorshipCenterD
 
Medical Technology Corporation: Supply Chain Strategy
daretruong
 
AI presentation for everyone in every fields
dodinhkhai1
 
CHALLENGIES FACING THEOLOGICAL EDUCATION IN NIGERIA: STRATEGIES FOR IMPROVEMENT
PREVAILERS THEOLOGICAL SCHOOL FCT ABUJA
 
Mining RACE Newsletter 10 - first half of 2025
Mining RACE
 
Food_and_Drink_Bahasa_Inggris_Kelas_5.pptx
debbystevani36
 
A brief History of counseling in Social Work.pptx
Josaya Injesi
 
From 0 to Gemini: a Workshop created by GDG Firenze
gdgflorence
 
English_Book_2 part 2 let reviewers news
2022mimiacadserver
 
BARRIERS TO EFFECTIVE COMMUNICATION.pptx
shraddham25
 
Buy Old GitHub Accounts -Trusted Sellers
GitHub Account
 
Blended Family Future, the Mayflower and You
UCG NWA
 
Presentationexpressions You are student leader and have just come from a stud...
BENSTARBEATZ
 
2025-07-13 Abraham 07 (shared slides).pptx
Dale Wells
 
Bob Stewart Humble Obedience 07-13-2025.pptx
FamilyWorshipCenterD
 
English_Book_1 part 1 LET Reviewers NEw-
2022mimiacadserver
 
Wireless Communications Course lecture1.ppt
abdullahyaqot2015
 

Compiler: Programming Language= Assignments and statements

  • 1. COMPILERS: PROGRAMMING LANGUAGES ASSIGNMENTS - STATEMENTS. 1 Presentation By: Geo S. Mariyan (Master in Computer Science)
  • 2. Assignment - Introduction • Assignment is to "assign a pre declared variable with some value or by the value of another variable of the same data type. This is done anywhere in body of the program. For E.g. : n=9 or m=5 then, n=5 ! assigns value 5 to n • Initialization is telling compiler to allocate a memory to the initialized variable so that compiler can know that this variable is going to store some value. 2
  • 3. ASSIGNMENT – Symbolic Representation • ASSIGNMENT: The Basic Operation for changing the binding of the value to the data object. • Assignment also returns the value, which is a data object containing the copy of a value assigned. 3
  • 4. Ex : int a; Initializing 'a' as of type int Assignment means proving a particular value to any variable. Ex: int a=2; a in assigned a value to 2. This is purely assignment and assignment can be done n no. of times in a program. There is no such restriction on it. Assignment throws away the old value of a variable and replacing it with a new one. It can be done anywhere in the whole program. 4
  • 5. l- and r- values • An lvalue can appear on the left side of an assignment operator, whereas an rvalue can appear on the right side. • "lvalue" and "rvalue" are so named because of where each of them can appear in an assignment operation. • ex: int a, b; • a = 4; • b = a; • In the third line of that example, "b" is the lvalue, and "a" is the rvalue, whereas it was the lvalue in line. • This illustrates an important point: An lvalue can also be an rvalue. 5
  • 6. Assignment Operators • An assignment operator is the operator used to assign a new value to a variable, property, event or indexer element. • Assignment operators can also be used for logical operations such as bitwise logical operations or operations on integral operands and Boolean operands. • Unlike in C++, assignment operators in C# cannot be overloaded directly, but the user-defined types can overload the operators like +, -, /, etc. This allows the assignment operator to be used with those types. 6
  • 7. Characteristics of Assignment Operators: • The different assignment operators are based on the type of operation performed between two operands such as addition (+=), subtraction, (-=), etc. The meaning of the operator symbol used depends on the type of the operands. • Assignment operators are right-associative, which means they are grouped from right to left. • Although assignment using assignment operator (a += b) achieves the same result as that without ( =a +b), the difference between the two ways is that unlike in the latter example, "a" is evaluated only once. 7
  • 8. Practice with Assignment Operators The assignment operator expects the type of both the left- and right-hand side to be the same for successful assignment. Example: i += 24 i *= x 8
  • 9. Variant forms of Assignment •Augmented Assignment •Chained Assignment •Parallel Assignment 9
  • 10. • Augmented assignment: The case where the assigned value depends on a previous one is so common that many imperative languages, most notably C and the majority of its descendants, provide special operators called Augmented assignment ex: *=, so a = 2*a can instead be written as a *= 2 • Chained assignment: A statement like w = x = y = z is called a chained assignment in which the value of z is assigned to multiple variables w, x, and y. Chained assignments are often used to initialize multiple variables, as in •example: a = b = c = d = f = 0 10
  • 11. Parallel Assignment: Some programming languages, such as Go, JavaScript (since, Maple, Perl, Python, REBOL, Ruby, and Windows Power Shell allow several variables to be assigned in parallel, with syntax like: ex: a, b := 0, 1 which simultaneously assigns 0 to a and 1 to b. This is most often known as parallel assignment. 11
  • 12. Assignment statements • Once a variable is declared, it can be assigned values multiple times in a program; for example: int num; // num declared, uninitialized num = 3; // num assigned 3 num = num + 1; // num assigned 3 + 1 (4) num = 15 / num; // num assigned 15 / 4 12
  • 13. Implementation of Assignment: • Compiler can implement the assignment A := B • The Compiler generates code to compute the r-value and B into some register r-value of B into some register r • If the data types of A and B are incompatible, the compiler generates code to convert the r-value of B to a type appropriate for A. • If necessary, the compiler generates the code to determine the l-value of A. (if A is in primitive type , no code is needed) • Finally, the compiler generates code to store the contents of register r into the l-values of A. 13
  • 14. Assignment compatibility • When a variable is declared, the data type in the declaration indicates the nature of the values the variable is capable of storing. • For example, an int variable can store a whole number, a char variable can store a character, and a double variable can store a real number. • The value assigned to the variable must be compatible with its data type. 14
  • 15. •Java is a strongly-typed language. •This means that, for the most part, you can only assign a value of a particular data type to a variable of the same type •Some examples: int x = -2; // this is fine; -2 is an integer char c = ‘2’; // this is OK also x = 2.5; // syntax error: 2.5 is a double value, not an int c = 2; // also an error; 2 is an int value, not a char 15
  • 16. Assignment Statement Variety: = FORTRAN, C, C++, Java = Can be bad if it is overloaded for the relational operator for equality. • Example C: a=b=c • In the C statement A = B = C, the value of C is assigned to B, and the value of B is assigned to A. 16
  • 17. Statements: Definition : A statement in programming context is a single complete programming instruction that is written as code. The Elementary action of evaluation, assignment and control of evaluation orders are specified by the statements of the programming language . Statements can have diverse forms and languages. 17
  • 18. Function Call Statement •Certain function calls, such as the MESSAGE function, can be a statement on their own. They are known as function call statements • 18
  • 19. The Statement Separator A single programming statement may span several code lines; one code line may consist of multiple statements. Therefore, the C compiler must be able to detect when one statement ends and another statement begins. [ <statement> { ; <statement> } ] Example : Integer Num:=10; 19
  • 20. Assignment Statement In computer programming, an assignment statement sets and/or re-sets the value stored in the storage location(s) denoted by a variable name; in other words, it copies a value into the variable. In most imperative programming languages, the assignment statement (or expression) is a fundamental construct. The syntax of an assignment statement is almost as easy as the syntax of the function call statement. The syntax is as follows: <variable> := <expression> 20
  • 21. Assignment Statement • Assignment statements can be in the following two forms 1) x := op y 2) x := y op z • First statement op is a unary operation. Essential unary operations are unary logical negation, shift operators and conversion operators. • Second statement op is a binary arithmetic or logical operator. 21
  • 22. Assignment Operator • An assignment operator is the operator used to assign a new value to a variable, property, event or indexer element in C# programming language. • Assignment operators can also be used for logical operations such as bitwise logical operations or operations on integral operands and Boolean operands. • The “colon equals” (:=) is known as the assignment operator. You use it to assign a value or an expression that evaluates to a value to a variable. • := 22
  • 23. Jump Statements • The jump statements are the goto statement, the continue statement, the break statement, and the return statement. • The source statement like if and while-do cause jump in the control flow through three address code so any statement in three address code can be given label to make it the target of a jump. 23
  • 24. Indexed Assignment • Indexed assignment of the form A:=B[I] and A[I]:=B. the first statement sets A to the value in the location I memory units beyond location B. • In the later statement A [I]:=B, sets the location I units beyond A to the value of B. • In Both instructions A, B, and I are assumed to refer data objects and will represented by pointers to the symbol table. 24
  • 25. Address and Pointer Assignment • Address and pointer assignment x := &y x := *y *x := y • First statement, sets the value of x to be the location of y. • In x := *y, here y is a pointer or temporary whose r-value is a location. The r-value of x is made equal to the contents of that location. • *x := y sets the r-value of the object pointed to by a to the r-value of y. 25
  • 26. Assignment Operations • Most basic statements for initializing variables • General syntax: • variable = expression; • Example: • length = 25; • Expression • Any combination of constants and variables that can be evaluated to yield a result 26
  • 27. •All variables used in an expression must previously have been given valid values. •Must be a variable listed immediately to the left of the equal sign. •Has lower precedence than any other arithmetic operator. 27
  • 28. Assignment Statements: Compound Operators •A shorthand method of specifying a commonly needed form of assignment. •Introduced in ALGOL; adopted by C Example: a = a + b is written as a += b •Unary assignment operators in C-based languages combine increment and decrement operations with assignment. 28
  • 29. Examples: • sum = ++count (count incremented, then assigned to sum) • sum = count++ (count assigned to sum, then incremented) • count++ (count incremented) • -count++ (count incremented then negated) 29
  • 30. Assignment as an Expression • In C, C++, and Java, the assignment statement produces a result and can be used as operands • An example: while ((ch=getchar())!= EndOfFile){…} ch = getchar() is carried out; the result (assigned to ch) is used as a conditional value for the while statement 30
  • 31. Simple and Compound Statements • Simple Statement: A Simple statement is one which does not contain any augmented statement. • Read, Assignment and goto are the three examples of simple statements. • In certain languages, a program may be regarded as a sequence of simple statements. (e.g., BASIC, SNOBOL) • Compound Statement: A Compound Statement is one that may contain one or more embedded statements. • The logical IF in FORTRAN • IF (condition) statement 31
  • 32. Compound statements: The Compound Statement enable computation that logically belong together and be grouped together syntactically. • This ability of grouping together helps make program readable. Example of Compound statement: 1. If condition then statement 2. If condition then statement else statement 3. While condition do statement 32
  • 33. Explanation: • The if-then and if-then-else statements allows all actions that apply for the value of condition to be grouped together. • The compound statements permits the sequence of the statements to be used wherever one may appear. • The while statements is to establish the loops with arbitrary loop control conditions. • In compound statement in other languages the syntax may be widely different. •Note*: The test for the condition is performed before the statements allowing the loops to be executed zero times if necessary. 33
  • 34. Types of Statements 1. Conditional Statements. 2. Sequential Statements. 3. Control Statements. 4.Structural Statements. 5. Declaration Statements. 6.Input Statements. 7. Output Statements. 34
  • 35. Conditional Statements: • In Conditional statements are features of a programming language, which perform different computations or actions depending on whether a programmer specified boolean condition evaluates to true or false. 35
  • 36. 36 Conditional statement is a set of rules performed if a certain condition is met. Below are some examples of conditional statements in programming. this last example will print if it is greater than 10, less than 10 or equal to 10.
  • 37. Sequential Statement: • In most languages , control automatically flows from one statement to the next. • Certain statements such as goto, break, call and return deliberately alter the flow of control. • There has been considerable debate as to what statements are best suited for creating easy to understand flow-of- control patterns in programs. • The Sequential statement has been the focus and it permits the arbitrary flow-of-control patterns, including those that are difficult to comprehend. 37
  • 39. Control Structure: • A control statement is a statement that determines whether other statements will be executed. • An if statement decides whether to execute another statement, or decides which of two statements to execute. • A loop decides how many times to execute another statement. • while loops test whether a condition is true before executing the controlled statement. • do-while loops test whether a condition is true after executing controlled statement. 39
  • 40. 40 •The for loops are (typically) used to execute the controlled statement a given number of times. •A switch statement decides which of several statements to execute.
  • 41. Structural Statements: • Certain Statements such as END serve to group Simple statements into structures. • Following the structured program theorem: • "Sequence: Ordered statements or subroutines executed in sequence. • "Selection: One or a number of statements is executed depending on the state of the program. This is usually expressed with keywords such as if..then..else. 41
  • 42. 42 Iteration: a statement or block is executed until the program reaches a certain state, or operations have been applied to every element of a collection. This is usually expressed with keywords such as while, repeat, for or do..until Recursion: a statement is executed by repeatedly calling itself until termination conditions are met.
  • 43. Declaration Statements: • These statements generally produce no executable code. • Their semantic effect is to uniform the compiler about the attributes of names encountered in the program . • The compiler implements’ a declaration statement by storing the attribute information contained therein in the symbol table and then consulting this information whenever declared names are used in program. 43
  • 44. 44 •Declaration of a variable serves two purposes: It associates a type and an identifier (or name) with the variable. The type allows the compiler to interpret statements correctly. •Declarations are most commonly used for functions, variables, constants, and classes, but can also be used for other entities such as enumerations and type definitions.
  • 45. Input & Output Statements: • These statements serve the role as their names . • In many languages they are implemented by library subroutines made available by operating system to control input/output devices. • It convert data to human readable form. • In variety of languages we see formats, which are strings of information about how data is to be interpreted or Expressed (Read or Write) 45
  • 47. 47

Editor's Notes

  • #14: Primitive types are the most basic data types available within the Java language. There are 8: boolean , byte , char , short , int , long , float and double .
  • #22: The unary operators operate on a single operand and following are the examples of Unary operators: The increment (++) and decrement (--) operators. The unaryminus (-) operator.  Binary operators are Boolean expression such as Boolean Operators are simple words (AND, OR, NOT or AND NOT) used as conjunctions to combine or exclude keywords.
  • #30: Increment means adding by 1 if it counts by 1.
  • #32: An augmented is generally used to replace a statement where an operator takes a variable as one of its arguments and then assigns the result back to the same variable. A simple example is x += 1 which is expanded to x = x + 1