SlideShare a Scribd company logo
1 of 7
EXPRESSIONS
An expression is a sequence of operands and operators that reduces to a single
value. Expressions can be simple or complex. An operator is a syntactical token
that requires an action to be taken. An operand is an object on which an
operation is performed; it receives an operator's action.
 A simple expression contains only one operator.
For example 2+5 is a simple expression whose value is 7; similarly, -a is a
simple expression.
 A complex expression contains more than one operator.
An example of a complex expression is 2 + 5 * 7. To evaluate a complex
expression, we reduce it to a series of simple expressions.
We first evaluate the simple expression (5 * 7) and then the expression 2 + 35,
giving a result of 37.
Every language has operators whose actions are clearly specified in the
language syntax. The order in which the operators in a complex expression are
evaluated is determined by a set of priorities known as precedence; the
higher the precedence, the earlier the expression containing the operator is
evaluated.
If two operators with same precedence occur in a complex expression, another
attribute of an operator, its associativity, takes control.
Associativity
is the parsing direction used to evaluate an expression. It can be either left-to-
right or right-to-left. When two operators with the same precedence occur in an
expression and their associativity is left-to-right, the left operator is evaluated
first.
For example, in the expression 3 * 4 / 6, there are two operators, multiplication
and division, with the same precedence and left-to-right associativity. Therefore,
the multiplication is evaluated before the division.
An expression always reduces to a single value.
6*2/( 2+1 * 2/3 +6) +8 * (8/4)
Example:
Infix, prefix and postfix are three different but equivalent notations of writing
algebraic expressions.
a. INFIX NOTATION
 The traditional method of writing mathematical expressions is called as
the infix expressions.
 It is of the form <operand><operator><operand>.
 As the name suggests, here the operator is fixed inside between the
operands. e.g. A+B here the plus operator is placed inside between the
two operators, (A*B)/Q.
 Such expression are easy to understand and evaluate for human beings.
However computer finds it difficult to parse - Information is needed about
operator precedence and associativity rules, and brackets which override
these rules.
 Hence we have postfix and prefix notations which make the computer take
less effort to solve the problem.
b. POSTFIX NOTATION
 The postfix expression as the name suggests has the operator placed right
after the two operands.
 It is of the form <operand><operand><operator>
 In the infix expressions, it is difficult to keep track of the operator
precedence whereas here the postfix expression itself determines the
precedence of operators (which is done by the placement of operators)
i.e. the operator which occurs first operates on the operand.
 E.g. PQ-C/, here – operation is done on P and Q and then / is applied on C
and the previous result.
 A postfix expression is parenthesis-free expression. For evaluation, we
evaluate it from left-to-right.
Infix expression Postfix expression
(P+Q)*(M-N) PQ+MN-*
(P+Q) / (M-N) - (A*B) PQ+MN-/AB*-
c. PREFIX NOTATION
 The prefix expression as the name suggests has the operator placed before
the operand is specified.
 It is of the form < operator > < operand > < operand >.
 It works entirely in same manner as the postfix expression.
 While evaluating a prefix expression, the operators are applied to the
operands immediately on the right of the operator.
 For evaluation, we evaluate it from left-to-right. Prefix expressions are also
called as polish notation.
Infix expression Postfix expression
(P+Q)*(M-N) *+PQ-MN
(P+Q) / (M-N) - (A*B) -/+PQ-MN*AB
A + B * C + D
(A + B) * (C + D)
A * B + C * D
A + B + C + D

More Related Content

What's hot

What is analytic functions
What is analytic functionsWhat is analytic functions
What is analytic functions
Tarun Gehlot
 
Applications of analytic functions and vector calculus
Applications of analytic functions and vector calculusApplications of analytic functions and vector calculus
Applications of analytic functions and vector calculus
Poojith Chowdhary
 

What's hot (19)

Week2 dq4
Week2 dq4Week2 dq4
Week2 dq4
 
Java basic operators
Java basic operatorsJava basic operators
Java basic operators
 
05 operators
05   operators05   operators
05 operators
 
Java 2
Java 2Java 2
Java 2
 
An executable model for an Intelligent Vehicle Control System
An executable model for an Intelligent Vehicle Control SystemAn executable model for an Intelligent Vehicle Control System
An executable model for an Intelligent Vehicle Control System
 
recursive problem_solving
recursive problem_solvingrecursive problem_solving
recursive problem_solving
 
What is analytic functions
What is analytic functionsWhat is analytic functions
What is analytic functions
 
Applications of analytic functions and vector calculus
Applications of analytic functions and vector calculusApplications of analytic functions and vector calculus
Applications of analytic functions and vector calculus
 
Handout # 4 functions + scopes
Handout # 4   functions + scopes Handout # 4   functions + scopes
Handout # 4 functions + scopes
 
Lecture03(c expressions & operators)
Lecture03(c expressions & operators)Lecture03(c expressions & operators)
Lecture03(c expressions & operators)
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Control structures functions and modules in python programming
Control structures functions and modules in python programmingControl structures functions and modules in python programming
Control structures functions and modules in python programming
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Subroutines in perl
Subroutines in perlSubroutines in perl
Subroutines in perl
 
Type Conversion, Precedence and Associativity
Type Conversion, Precedence and AssociativityType Conversion, Precedence and Associativity
Type Conversion, Precedence and Associativity
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Operators
OperatorsOperators
Operators
 
LINUX:Control statements in shell programming
LINUX:Control statements in shell programmingLINUX:Control statements in shell programming
LINUX:Control statements in shell programming
 
Functions
FunctionsFunctions
Functions
 

Similar to 11 EXPRESSIONS.pptx

9-Removal of ambiguity, precedence and associativity-26-05-2023.docx
9-Removal of ambiguity, precedence and associativity-26-05-2023.docx9-Removal of ambiguity, precedence and associativity-26-05-2023.docx
9-Removal of ambiguity, precedence and associativity-26-05-2023.docx
venkatapranaykumarGa
 
Operator & Expression in c++
Operator & Expression in c++Operator & Expression in c++
Operator & Expression in c++
bajiajugal
 

Similar to 11 EXPRESSIONS.pptx (20)

9-Removal of ambiguity, precedence and associativity-26-05-2023.docx
9-Removal of ambiguity, precedence and associativity-26-05-2023.docx9-Removal of ambiguity, precedence and associativity-26-05-2023.docx
9-Removal of ambiguity, precedence and associativity-26-05-2023.docx
 
c programming2.pptx
c programming2.pptxc programming2.pptx
c programming2.pptx
 
C# operators
C# operatorsC# operators
C# operators
 
Unit 2 application of stack
Unit 2  application of stack Unit 2  application of stack
Unit 2 application of stack
 
Operator.ppt
Operator.pptOperator.ppt
Operator.ppt
 
Operator precedence and associativity
Operator precedence and associativityOperator precedence and associativity
Operator precedence and associativity
 
OCA JAVA - 3 Programming with Java Operators
 OCA JAVA - 3 Programming with Java Operators OCA JAVA - 3 Programming with Java Operators
OCA JAVA - 3 Programming with Java Operators
 
Operators
OperatorsOperators
Operators
 
Lecture_04.2.pptx
Lecture_04.2.pptxLecture_04.2.pptx
Lecture_04.2.pptx
 
Computer programming in C. Library functions in C.
Computer programming in C. Library functions in C.Computer programming in C. Library functions in C.
Computer programming in C. Library functions in C.
 
Operator & Expression in c++
Operator & Expression in c++Operator & Expression in c++
Operator & Expression in c++
 
Mycasestudy
MycasestudyMycasestudy
Mycasestudy
 
Data structure week y 5 1
Data structure week y 5 1Data structure week y 5 1
Data structure week y 5 1
 
Conditional and special operators
Conditional and special operatorsConditional and special operators
Conditional and special operators
 
Unit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cUnit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in c
 
C operators
C operatorsC operators
C operators
 
decisions
decisionsdecisions
decisions
 
Types of Operators in C
Types of Operators in CTypes of Operators in C
Types of Operators in C
 
Introduction to Python Values, Variables Data Types Chapter 2
Introduction to Python  Values, Variables Data Types Chapter 2Introduction to Python  Values, Variables Data Types Chapter 2
Introduction to Python Values, Variables Data Types Chapter 2
 
Polish Notation In Data Structure
Polish Notation In Data StructurePolish Notation In Data Structure
Polish Notation In Data Structure
 

Recently uploaded

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 

11 EXPRESSIONS.pptx

  • 1. EXPRESSIONS An expression is a sequence of operands and operators that reduces to a single value. Expressions can be simple or complex. An operator is a syntactical token that requires an action to be taken. An operand is an object on which an operation is performed; it receives an operator's action.  A simple expression contains only one operator. For example 2+5 is a simple expression whose value is 7; similarly, -a is a simple expression.  A complex expression contains more than one operator. An example of a complex expression is 2 + 5 * 7. To evaluate a complex expression, we reduce it to a series of simple expressions. We first evaluate the simple expression (5 * 7) and then the expression 2 + 35, giving a result of 37. Every language has operators whose actions are clearly specified in the language syntax. The order in which the operators in a complex expression are evaluated is determined by a set of priorities known as precedence; the higher the precedence, the earlier the expression containing the operator is evaluated.
  • 2.
  • 3. If two operators with same precedence occur in a complex expression, another attribute of an operator, its associativity, takes control. Associativity is the parsing direction used to evaluate an expression. It can be either left-to- right or right-to-left. When two operators with the same precedence occur in an expression and their associativity is left-to-right, the left operator is evaluated first. For example, in the expression 3 * 4 / 6, there are two operators, multiplication and division, with the same precedence and left-to-right associativity. Therefore, the multiplication is evaluated before the division. An expression always reduces to a single value. 6*2/( 2+1 * 2/3 +6) +8 * (8/4) Example:
  • 4. Infix, prefix and postfix are three different but equivalent notations of writing algebraic expressions. a. INFIX NOTATION  The traditional method of writing mathematical expressions is called as the infix expressions.  It is of the form <operand><operator><operand>.  As the name suggests, here the operator is fixed inside between the operands. e.g. A+B here the plus operator is placed inside between the two operators, (A*B)/Q.  Such expression are easy to understand and evaluate for human beings. However computer finds it difficult to parse - Information is needed about operator precedence and associativity rules, and brackets which override these rules.  Hence we have postfix and prefix notations which make the computer take less effort to solve the problem.
  • 5. b. POSTFIX NOTATION  The postfix expression as the name suggests has the operator placed right after the two operands.  It is of the form <operand><operand><operator>  In the infix expressions, it is difficult to keep track of the operator precedence whereas here the postfix expression itself determines the precedence of operators (which is done by the placement of operators) i.e. the operator which occurs first operates on the operand.  E.g. PQ-C/, here – operation is done on P and Q and then / is applied on C and the previous result.  A postfix expression is parenthesis-free expression. For evaluation, we evaluate it from left-to-right. Infix expression Postfix expression (P+Q)*(M-N) PQ+MN-* (P+Q) / (M-N) - (A*B) PQ+MN-/AB*-
  • 6. c. PREFIX NOTATION  The prefix expression as the name suggests has the operator placed before the operand is specified.  It is of the form < operator > < operand > < operand >.  It works entirely in same manner as the postfix expression.  While evaluating a prefix expression, the operators are applied to the operands immediately on the right of the operator.  For evaluation, we evaluate it from left-to-right. Prefix expressions are also called as polish notation. Infix expression Postfix expression (P+Q)*(M-N) *+PQ-MN (P+Q) / (M-N) - (A*B) -/+PQ-MN*AB
  • 7. A + B * C + D (A + B) * (C + D) A * B + C * D A + B + C + D