Featured Posts

Implicit and Explicit sequence Control


Implicit and Explicit Sequence Control :->

     A sequence control can be either implicit or explicit.
     Implicit means default i.e the logic or control defined exclusively by the language unless modified by some programmer through explicit or external sequence control.  Example GOTO statements in C or break continue.
     Sequence control is nothing but the flow of a program.
     Suppose we write a small program using if-else ladder.  So, the flow is basically if statements (i.e the condition true) or else statements (i.e the condition is false).  Thus there may be two flow of controls depends upon the condition provided by the user and in any program flow control is started from the keyword main.
    Sequence control is primarily categorized in four groups :-
-> Expression ( Precedence rule and parenthesis ).
-> Statements ( Conditional and iterations statements).
-> Declarative Programming ( declaration of function ).
-> Subprogram ( Subprogram Calls ).

# Expression determines how data are manipulated and changed by a program.
# Statements they are nothing but group of expressions.
# Declarative Programming :-> is an execution model that does not depend on statements and causes execution.
# Subprograms they are call to any procedure or co-routine i.e a way of transfer execution. from one statement to other.

# Two type of controls we have :-

1. Sequence Control :->  It control the order of execution of operations.
2. Data Controls :->  It control the transmission of data among subprogram of a program.
  • Structures used in expressions - Precedence rules and parenthesis.
  • Structures used between group of statements - Conditional and iterative statements.
  • Structures used between subprograms - Subprogram calls.

Sequencing with arithmetic expression :->

For a smaller formula such as 
A = B + C - D.
This will need  C-D as 1 instruction and store the result as T1 i.e C - D = T1.
B + T1 = T2 as second & A = T2, third.
Thus it need three instruction and  two temporary variables.
For Example ( a + b )*( c -a )
-> Advantages of notations.
*  No ambiguity and no parenthesis needed.

Prefix Notation :-> Operator come first which is followed by the operands ( a + b ) * ( c - a )
its Prefix Notation = *+ab-ca.

Postfix Notation :-> i.e A operator follows its operands ( a + b ) * ( c - a ) its Postfix notation is ab+ca-*.

Infix Notation
              Only suitable for binary operations and also produces ambiguity in an expression  unless we used parenthesis.
For example 3*4+6 if we doesn't know the precedence rule or also we doesn't know any parenthesis rules.
This expression remains ambiguous.
But prefix and postfix expressions are easier to implement using stacks.

* Hierarchy of operations :->  The operator that may occur in expressions are placed in a hierarchy or precedence order i.e the operation have higher precedence must have to be executed first.

Associativity :->  We can also use associativity rule instead of precedence rules.
For eg we have a + b = c.

Left Associativity  :->  we can solve this expression from left to right i.e '+' is evaluated before '-'.
OR either we can solve this by right to left i.e '-' has to evaluated before '+' i.e Right Associativity.
Precedence Order

*, abs, not -> highest precedence
*, /,  mod, rem
+, -
+, - , &
=, less then equal to, less then, greater then, greater than equal to.

Post a Comment


www.posthatke.com. Powered by Blogger.
Copyright © www.posthatke.com | Blogger Templates | Designed By posthatke.com