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)

Data Types & Variables in JAVA
Data Types & Variables in JAVA
Ankita Totala
 
Symbolic Mathematics
Symbolic Mathematics
saadurrehman35
 
Predictive parser
Predictive parser
Jothi Lakshmi
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compiler
Iffat Anjum
 
Introduction to ASP.NET
Introduction to ASP.NET
Rajkumarsoy
 
Arrays in Java
Arrays in Java
Naz Abdalla
 
Procedural vs. object oriented programming
Procedural vs. object oriented programming
Haris Bin Zahid
 
Classes objects in java
Classes objects in java
Madishetty Prathibha
 
Parsing
Parsing
khush_boo31
 
P code
P code
Sandeep Rv
 
Relational Data Model Introduction
Relational Data Model Introduction
Nishant Munjal
 
Vectors in Java
Vectors in Java
Abhilash Nair
 
Encapsulation C++
Encapsulation C++
Hashim Hashim
 
OOPS In JAVA.pptx
OOPS In JAVA.pptx
Sachin33417
 
Enumeration in Java Explained | Java Tutorial | Edureka
Enumeration in Java Explained | Java Tutorial | Edureka
Edureka!
 
Java threads
Java threads
Prabhakaran V M
 
Inheritance in c++
Inheritance in c++
Vineeta Garg
 
Java Data Types
Java Data Types
Spotle.ai
 
Integrity Constraints
Integrity Constraints
Megha yadav
 
Exception Handling in JAVA
Exception Handling in JAVA
SURIT DATTA
 
Data Types & Variables in JAVA
Data Types & Variables in JAVA
Ankita Totala
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compiler
Iffat Anjum
 
Introduction to ASP.NET
Introduction to ASP.NET
Rajkumarsoy
 
Procedural vs. object oriented programming
Procedural vs. object oriented programming
Haris Bin Zahid
 
Relational Data Model Introduction
Relational Data Model Introduction
Nishant Munjal
 
OOPS In JAVA.pptx
OOPS In JAVA.pptx
Sachin33417
 
Enumeration in Java Explained | Java Tutorial | Edureka
Enumeration in Java Explained | Java Tutorial | Edureka
Edureka!
 
Inheritance in c++
Inheritance in c++
Vineeta Garg
 
Java Data Types
Java Data Types
Spotle.ai
 
Integrity Constraints
Integrity Constraints
Megha yadav
 
Exception Handling in JAVA
Exception Handling in JAVA
SURIT DATTA
 

Viewers also liked (20)

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

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

Programming in java basics
Programming in java basics
LovelitJose
 
2 EPT 162 Lecture 2
2 EPT 162 Lecture 2
Don Dooley
 
Introduction to c
Introduction to c
sunila tharagaturi
 
CSC111-Chap_02.pdf
CSC111-Chap_02.pdf
2b75fd3051
 
Embedded C The IoT Academy
Embedded C The IoT Academy
The IOT Academy
 
chapter 5.ppt
chapter 5.ppt
ThedronBerhanu
 
JAVA programming language made easy.pptx
JAVA programming language made easy.pptx
Sunila31
 
Data types, Variables, Expressions & Arithmetic Operators in java
Data types, Variables, Expressions & Arithmetic Operators in java
Javed Rashid
 
Control structure repetition Tito Lacbayen
Control structure repetition Tito Lacbayen
LacbayenEchaviaTitoJ
 
1) VariableIn programming, a variable is a container (storage area).pdf
1) VariableIn programming, a variable is a container (storage area).pdf
annamalassociates
 
C Programming Unit-1
C Programming Unit-1
Vikram Nandini
 
java or oops class not in kerala polytechnic 4rth semester nots j
java or oops class not in kerala polytechnic 4rth semester nots j
ishorishore
 
CSE 1201: Structured Programming Language
CSE 1201: Structured Programming Language
Zubayer Farazi
 
Java fundamentals
Java fundamentals
HCMUTE
 
Mit6 087 iap10_lec02
Mit6 087 iap10_lec02
John Lawrence
 
comp 122 Chapter 2.pptx,language semantics
comp 122 Chapter 2.pptx,language semantics
floraaluoch3
 
1. overview of c
1. overview of c
amar kakde
 
C programming day#1
C programming day#1
Mohamed Fawzy
 
OOP Using Java Ch2 all about oop .pptx
OOP Using Java Ch2 all about oop .pptx
doopagamer
 
Lecture1.pdf
Lecture1.pdf
SakhilejasonMsibi
 
Programming in java basics
Programming in java basics
LovelitJose
 
2 EPT 162 Lecture 2
2 EPT 162 Lecture 2
Don Dooley
 
CSC111-Chap_02.pdf
CSC111-Chap_02.pdf
2b75fd3051
 
Embedded C The IoT Academy
Embedded C The IoT Academy
The IOT Academy
 
JAVA programming language made easy.pptx
JAVA programming language made easy.pptx
Sunila31
 
Data types, Variables, Expressions & Arithmetic Operators in java
Data types, Variables, Expressions & Arithmetic Operators in java
Javed Rashid
 
Control structure repetition Tito Lacbayen
Control structure repetition Tito Lacbayen
LacbayenEchaviaTitoJ
 
1) VariableIn programming, a variable is a container (storage area).pdf
1) VariableIn programming, a variable is a container (storage area).pdf
annamalassociates
 
java or oops class not in kerala polytechnic 4rth semester nots j
java or oops class not in kerala polytechnic 4rth semester nots j
ishorishore
 
CSE 1201: Structured Programming Language
CSE 1201: Structured Programming Language
Zubayer Farazi
 
Java fundamentals
Java fundamentals
HCMUTE
 
Mit6 087 iap10_lec02
Mit6 087 iap10_lec02
John Lawrence
 
comp 122 Chapter 2.pptx,language semantics
comp 122 Chapter 2.pptx,language semantics
floraaluoch3
 
1. overview of c
1. overview of c
amar kakde
 
OOP Using Java Ch2 all about oop .pptx
OOP Using Java Ch2 all about oop .pptx
doopagamer
 
Ad

Recently uploaded (20)

Seminar Presented by Natnael Dechasa Title: Brain Cheat Codes: The Science-Ba...
Seminar Presented by Natnael Dechasa Title: Brain Cheat Codes: The Science-Ba...
Nati1986
 
Road safety presentation for high school
Road safety presentation for high school
nikhithavarghese77
 
Bob Stewart Acts 17 Study 06 11 2025.pptx
Bob Stewart Acts 17 Study 06 11 2025.pptx
FamilyWorshipCenterD
 
FUTURE OF FITNESS 2025 KEYNOTE BRYAN OROURKE BEYOND ACTIV SINGAPORE 2025
FUTURE OF FITNESS 2025 KEYNOTE BRYAN OROURKE BEYOND ACTIV SINGAPORE 2025
Bryan K. O'Rourke
 
Media of Advertisement-How to choose it.pptx
Media of Advertisement-How to choose it.pptx
bugisatrioadiwibowo
 
2025-06-08 Abraham 02 (shared slides).pptx
2025-06-08 Abraham 02 (shared slides).pptx
Dale Wells
 
Food Truck Business Plan | Sakthi Sundar.pptx
Food Truck Business Plan | Sakthi Sundar.pptx
Sakthi Sundar
 
THE HISTORY AND EVOLUTION OF VARIOUS SWORDS.pdf
THE HISTORY AND EVOLUTION OF VARIOUS SWORDS.pdf
sethjamcam
 
Presenation - compensation plan - Mining Race - NEW - June 2025
Presenation - compensation plan - Mining Race - NEW - June 2025
Mining RACE
 
THE INTERIOR REVIEW MEDIA KIT - THE INTERIOR REVIEW
THE INTERIOR REVIEW MEDIA KIT - THE INTERIOR REVIEW
rspyamin
 
Diddy Baby oil making tutorial (natural ingresients.pptx
Diddy Baby oil making tutorial (natural ingresients.pptx
RanitMal
 
The Caribbean Challenge: Fostering Growth and Resilience Amidst Global Uncert...
The Caribbean Challenge: Fostering Growth and Resilience Amidst Global Uncert...
Caribbean Development Bank
 
From Idea to Impact: Maximizing Your Hackathon Performance
From Idea to Impact: Maximizing Your Hackathon Performance
outsystemspuneusergr
 
Sample work (PL Product Research) Joseph_Juntilla.pdf
Sample work (PL Product Research) Joseph_Juntilla.pdf
Joseph Juntilla
 
Retail Store Scavenger Hunt experience!!
Retail Store Scavenger Hunt experience!!
Samally Dávila
 
presentacion de Inspire Power Point.pptx
presentacion de Inspire Power Point.pptx
teamspro
 
Assesement_PPT Designer -----------Final
Assesement_PPT Designer -----------Final
RajeshKumarKumre
 
Pentecost Sunday A Promise of Power.pptx
Pentecost Sunday A Promise of Power.pptx
FamilyWorshipCenterD
 
Jadual Waktu dan Jadual Bertugas kelas.pptx
Jadual Waktu dan Jadual Bertugas kelas.pptx
roslan17
 
Personal letter personal letter personal letter.pptx
Personal letter personal letter personal letter.pptx
GedeJuliana2
 
Seminar Presented by Natnael Dechasa Title: Brain Cheat Codes: The Science-Ba...
Seminar Presented by Natnael Dechasa Title: Brain Cheat Codes: The Science-Ba...
Nati1986
 
Road safety presentation for high school
Road safety presentation for high school
nikhithavarghese77
 
Bob Stewart Acts 17 Study 06 11 2025.pptx
Bob Stewart Acts 17 Study 06 11 2025.pptx
FamilyWorshipCenterD
 
FUTURE OF FITNESS 2025 KEYNOTE BRYAN OROURKE BEYOND ACTIV SINGAPORE 2025
FUTURE OF FITNESS 2025 KEYNOTE BRYAN OROURKE BEYOND ACTIV SINGAPORE 2025
Bryan K. O'Rourke
 
Media of Advertisement-How to choose it.pptx
Media of Advertisement-How to choose it.pptx
bugisatrioadiwibowo
 
2025-06-08 Abraham 02 (shared slides).pptx
2025-06-08 Abraham 02 (shared slides).pptx
Dale Wells
 
Food Truck Business Plan | Sakthi Sundar.pptx
Food Truck Business Plan | Sakthi Sundar.pptx
Sakthi Sundar
 
THE HISTORY AND EVOLUTION OF VARIOUS SWORDS.pdf
THE HISTORY AND EVOLUTION OF VARIOUS SWORDS.pdf
sethjamcam
 
Presenation - compensation plan - Mining Race - NEW - June 2025
Presenation - compensation plan - Mining Race - NEW - June 2025
Mining RACE
 
THE INTERIOR REVIEW MEDIA KIT - THE INTERIOR REVIEW
THE INTERIOR REVIEW MEDIA KIT - THE INTERIOR REVIEW
rspyamin
 
Diddy Baby oil making tutorial (natural ingresients.pptx
Diddy Baby oil making tutorial (natural ingresients.pptx
RanitMal
 
The Caribbean Challenge: Fostering Growth and Resilience Amidst Global Uncert...
The Caribbean Challenge: Fostering Growth and Resilience Amidst Global Uncert...
Caribbean Development Bank
 
From Idea to Impact: Maximizing Your Hackathon Performance
From Idea to Impact: Maximizing Your Hackathon Performance
outsystemspuneusergr
 
Sample work (PL Product Research) Joseph_Juntilla.pdf
Sample work (PL Product Research) Joseph_Juntilla.pdf
Joseph Juntilla
 
Retail Store Scavenger Hunt experience!!
Retail Store Scavenger Hunt experience!!
Samally Dávila
 
presentacion de Inspire Power Point.pptx
presentacion de Inspire Power Point.pptx
teamspro
 
Assesement_PPT Designer -----------Final
Assesement_PPT Designer -----------Final
RajeshKumarKumre
 
Pentecost Sunday A Promise of Power.pptx
Pentecost Sunday A Promise of Power.pptx
FamilyWorshipCenterD
 
Jadual Waktu dan Jadual Bertugas kelas.pptx
Jadual Waktu dan Jadual Bertugas kelas.pptx
roslan17
 
Personal letter personal letter personal letter.pptx
Personal letter personal letter personal letter.pptx
GedeJuliana2
 

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