SlideShare una empresa de Scribd logo
1 de 20
Program 5
WAP to count number of whitespaces and newline characters
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str[200],ch;
int a=0,space=0,newline=0;
clrscr();
printf("n Enter a string(press escape to entering):");
ch=getche();
while((ch!=27)&&(a<199))
{
str[a]=ch;
if(str[a]==' ')
{
space++;
}
if(str[a]==13)
{

Seema                                                     1136619815
newline++;
printf("n");
}
a++;
ch=getche();
}
printf("n The number of lines used : %d",newline+1);
printf("n The number of spaces used is : %d",space);
getch();
}




Seema                                                   1136619815
OUTPUT




Seema            1136619815
Program 6
              WAP to implement the stack using array
#include<stdio.h>
#include<conio.h>
# define MAXSIZE 10
void push();
int pop();
void traverse();
int stack[MAXSIZE];
int top=-1;
void main()
{
int choice;
char ch;
do
{
clrscr();
printf("n1. PUSH");
printf("n2. POP");
printf("n3. TRAVERSE");


Seema                                              1136619815
printf("n4. Enter your choice");
scanf("%d",&choice);
switch(choice)
{
case 1: push();
        break;
case 2: printf("nThe deleted element is %d",pop());
        break;
case 3: traverse();
        break;
default: printf("nYou have entered wrong choice");
}
printf("nDo you wish to continue(Y/N)");
fflush(stdin);
scanf("%c",&ch);
}
while(ch=='Y'||ch=='N');
}
void push()
{
int item;


Seema                                                  1136619815
if(top==MAXSIZE-1)
{
printf("nThe stack is full");
getch();
exit(0);
}
else
{
printf("Enter the element to be inserted");
scanf("%d",&item);
top=top+1;
stack[top]=item;
}}
int pop()
{
int item;
if(top==-1)
{
printf("The stack is empty");
getch();
exit(0);


Seema                                         1136619815
}
else
{
item=stack[top];
top=top-1;
}
return(item);
}
void traverse()
{
int i;
if(top==-1)
{
printf("The stack is empty");
getch();
exit(0);
}
else
{
for(i=top;i>=0;i--)
         {


Seema                           1136619815
printf("nTraverse element is : ");
        printf("%d",stack[i]);
        }}}
                                        OUTPUT




Seema                                            1136619815
Program 7
WAP for computation of FIRST in grammer.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char t[5],nt[10],p[5][5],first[5][5],temp;
int i,j,not,nont,k=0,f=0;
clrscr();
printf("n Enter the no. of Non-terminals in the grammer:");
scanf("%d",&nont);
printf("n Enter the Non-terminals in the grammer:");
for(i=0;i<nont;i++)
{
scanf("n%c",&nt[i]);
}
printf("n Enter the no. of Terminals in the grammer:(Enter e for absiline)");
scanf("%d",&not);
printf("n Enter the Terminals in the grammer:");
for(i=0;i<not||t[i]=='$';i++)

Seema                                                                   1136619815
{
scanf("n%c",&t[i]);
}
for(i=0;i<nont;i++)
{
p[i][0]=nt[i];
first[i][0]=nt[i];
}
printf("nEnter the productions :n");
for(i=0;i<nont;i++)
{
scanf("%c",&temp);
printf("n Enter the production for %c(End the production with '$'sign):",p[i][0]);
for(j=0;p[i][j]!='$';)
{
j+=1;
scanf("%c",&p[i][j]);
}}
for(i=0;i<nont;i++)
{
printf("n The production for %c _>",p[i][0]);


Seema                                                                   1136619815
for(j=1;p[i][j]!='$';j++)
{
printf("%c",p[i][j]);
}}
for(i=0;i<nont;i++)
{
f=0;
for(j=1;p[i][j]!='$';j++)
{
for(k=0;k<not;k++)
{
if(f==1)
break;
if(p[i][j]==t[k])
{
first[i][j]=t[k];
first[i][j+1]='$';
f=1;
break;
}
else if(p[i][j]==nt[k])


Seema                       1136619815
{
first[i][j]=first[k][j] ;
if(first[i][j]=='e')
continue;
first[i][j+1]='$';
f=1;
break;
}}}}
for(i=0;i<nont;i++)
{
printf("nnThe first of %c->",first[i][0]);
for(j=1;first[i][j]!='$';j++)
{
printf("%ct",first[i][j]);
}}
getch();
}




Seema                                          1136619815
OUTPUT




Seema            1136619815
Program 8
WAP to check whether the string is a keyword or not.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int i,flag=0,m;
char s[5][10]={"if","else","goto","continue","return"},st[10];
clrscr() ;
printf("n Enter the string:");
gets(st);
for(i=0;i<5;i++)
{ m=strcmp(st,s[i]);
if(m==0)
flag=1; }
if(flag==0)
printf("nit is not a keyword");
else
printf("n it is a keyword");
getch(); }

Seema                                                            1136619815
OUTPUT




Seema            1136619815
Program 9
Study of converting NFA from Regular Expression.
Definition of Regular Expression
A regular expression is another representation of a regular language, and is defined
over an alphabet (defined as Σ). The simplest regular expressions are symbols from
λ, ∅, and symbols from Σ. Regular expressions can be built from these simple
regular expressions with parenthesis, in addition to union, Kleene star and
concatenation operators.

( , ) are used to help define the order of operations

* is the Kleene star

+ is the union operator

! is used to represent the empty string.

NONDETERMINISTIC FINITE AUTOMATA (NFA) - Automata with the
choice of two or more edges labeled with the same symbol or special edge labeled
with ε, edges that may be taken without using a symbol.

Example - the following NFA accepts either even number of a's or multiple of 3 a's;
the NFA must correctly choose which path to follow at the first transition.




An NFA is represented formally by a 5-tuple, (Q, Σ, Δ, q0, F), consisting of
        a finite set of states Q

Seema                                                                   1136619815
a finite set of input symbols Σ
        a transition relation Δ : Q × Σ → P(Q).
        an initial (or start) state q0 ∈ Q
        a set of states F distinguished as accepting (or final) states F ⊆ Q.

Here, P(Q) denotes the power set of Q.



CONVERTING A REGULAR EXPRESSION TO AN NFA




Seema                                                                     1136619815
Program 10
Study of Left Recursion.
Definition

"A grammar is left-recursive if we can find some non-terminal A which will
eventually derive a sentential form with itself as the left-symbol.

Immediate left recursion

Immediate left recursion occurs in rules of the form



where                and              are sequences of nonterminals and terminals,
and                doesn't start with             . For example, the rule



is immediately left-recursive. The recursive descent parser for this rule might look like:

function Expr()
{
  Expr(); match('+'); Term();
}

and a recursive descent parser would fall into infinite recursion when trying to
parse a grammar which contains this rule.

Indirect left recursion
Indirect left recursion in its simplest form could be defined as:




possibly giving the derivation

Seema                                                                       1136619815
More generally, for the nonterminals                 , indirect left recursion can be
defined as being of the form:




where                 are sequences of nonterminals and terminals.

Removing left recursion

Removing immediate left recursion
The general algorithm to remove immediate left recursion follows. Several
improvements to this method have been made, including the ones described in
"Removing Left Recursion from Context-Free Grammars", written by Robert C.
Moore.[5] For each rule of the form



where:

        A is a left-recursive nonterminal
                       is a sequence of nonterminals and terminals that is not null (
                       )
                       is a sequence of nonterminals and terminals that does not start
        with A.
replace the A-production by the production:



And create a new nonterminal




Seema                                                                     1136619815
This newly created symbol is often called the "tail", or the "rest".
As an example, consider the rule



This could be rewritten to avoid left recursion as




The last rule happens to be equivalent to the slightly shorter form




Seema                                                                  1136619815

Más contenido relacionado

La actualidad más candente

La actualidad más candente (19)

C++ control structure
C++ control structureC++ control structure
C++ control structure
 
4 operators, expressions &amp; statements
4  operators, expressions &amp; statements4  operators, expressions &amp; statements
4 operators, expressions &amp; statements
 
LET US C (5th EDITION) CHAPTER 4 ANSWERS
LET US C (5th EDITION) CHAPTER 4 ANSWERSLET US C (5th EDITION) CHAPTER 4 ANSWERS
LET US C (5th EDITION) CHAPTER 4 ANSWERS
 
week-16x
week-16xweek-16x
week-16x
 
week-6x
week-6xweek-6x
week-6x
 
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
 
Looping Statement And Flow Chart
 Looping Statement And Flow Chart Looping Statement And Flow Chart
Looping Statement And Flow Chart
 
Dti2143 chap 4 control statement part 2
Dti2143 chap 4 control statement part 2Dti2143 chap 4 control statement part 2
Dti2143 chap 4 control statement part 2
 
week-17x
week-17xweek-17x
week-17x
 
input
inputinput
input
 
C lab manaual
C lab manaualC lab manaual
C lab manaual
 
C PROGRAMS
C PROGRAMSC PROGRAMS
C PROGRAMS
 
C programms
C programmsC programms
C programms
 
All important c programby makhan kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan kumbhkar
 
SLIME
SLIMESLIME
SLIME
 
Control structures
Control structuresControl structures
Control structures
 
TMPA-2017: The Quest for Average Response Time
TMPA-2017: The Quest for Average Response TimeTMPA-2017: The Quest for Average Response Time
TMPA-2017: The Quest for Average Response Time
 
2 3. standard io
2 3. standard io2 3. standard io
2 3. standard io
 
05 queues
05 queues05 queues
05 queues
 

Destacado

Grooming Insights South Africa
Grooming Insights South Africa Grooming Insights South Africa
Grooming Insights South Africa Duncan Collins
 
Student village octagon btm case study v1
Student village   octagon btm case study v1Student village   octagon btm case study v1
Student village octagon btm case study v1Duncan Collins
 
3 Things Students want you to know.
3 Things Students want you to know. 3 Things Students want you to know.
3 Things Students want you to know. Duncan Collins
 
Student village sab regret nothing case study v1
Student village   sab regret nothing case study v1Student village   sab regret nothing case study v1
Student village sab regret nothing case study v1Duncan Collins
 
Adol brain
Adol brainAdol brain
Adol braindrrkbaxi
 
When Performance Deceives Desire-Dr. Vijay Kulkarni
When Performance Deceives Desire-Dr. Vijay KulkarniWhen Performance Deceives Desire-Dr. Vijay Kulkarni
When Performance Deceives Desire-Dr. Vijay KulkarniIndian Health Journal
 

Destacado (7)

Grooming Insights South Africa
Grooming Insights South Africa Grooming Insights South Africa
Grooming Insights South Africa
 
Student village octagon btm case study v1
Student village   octagon btm case study v1Student village   octagon btm case study v1
Student village octagon btm case study v1
 
3 Things Students want you to know.
3 Things Students want you to know. 3 Things Students want you to know.
3 Things Students want you to know.
 
Student village sab regret nothing case study v1
Student village   sab regret nothing case study v1Student village   sab regret nothing case study v1
Student village sab regret nothing case study v1
 
Adol brain
Adol brainAdol brain
Adol brain
 
Ужин отдай врагу
Ужин отдай врагуУжин отдай врагу
Ужин отдай врагу
 
When Performance Deceives Desire-Dr. Vijay Kulkarni
When Performance Deceives Desire-Dr. Vijay KulkarniWhen Performance Deceives Desire-Dr. Vijay Kulkarni
When Performance Deceives Desire-Dr. Vijay Kulkarni
 

Similar a Cd

Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branchingSaranya saran
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02Wingston
 
COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops Hemantha Kulathilake
 
STRING FUNCTION - Programming in C.pptx
STRING FUNCTION -  Programming in C.pptxSTRING FUNCTION -  Programming in C.pptx
STRING FUNCTION - Programming in C.pptxIndhu Periys
 
Diploma ii cfpc u-4 function, storage class and array and strings
Diploma ii  cfpc u-4 function, storage class and array and stringsDiploma ii  cfpc u-4 function, storage class and array and strings
Diploma ii cfpc u-4 function, storage class and array and stringsRai University
 
Unit 5 Foc
Unit 5 FocUnit 5 Foc
Unit 5 FocJAYA
 
Mcai pic u 4 function, storage class and array and strings
Mcai pic u 4 function, storage class and array and stringsMcai pic u 4 function, storage class and array and strings
Mcai pic u 4 function, storage class and array and stringsRai University
 
Btech i pic u-4 function, storage class and array and strings
Btech i pic u-4 function, storage class and array and stringsBtech i pic u-4 function, storage class and array and strings
Btech i pic u-4 function, storage class and array and stringsRai University
 
Functions torage class and array and strings-
Functions torage class and array and strings-Functions torage class and array and strings-
Functions torage class and array and strings-aneebkmct
 
function, storage class and array and strings
 function, storage class and array and strings function, storage class and array and strings
function, storage class and array and stringsRai University
 
Variadic functions
Variadic functionsVariadic functions
Variadic functionsramyaranjith
 
Input output functions
Input output functionsInput output functions
Input output functionshyderali123
 
An imperative study of c
An imperative study of cAn imperative study of c
An imperative study of cTushar B Kute
 
Bsc cs i pic u-4 function, storage class and array and strings
Bsc cs i pic u-4 function, storage class and array and stringsBsc cs i pic u-4 function, storage class and array and strings
Bsc cs i pic u-4 function, storage class and array and stringsRai University
 

Similar a Cd (20)

Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
 
String Manipulation Function and Header File Functions
String Manipulation Function and Header File FunctionsString Manipulation Function and Header File Functions
String Manipulation Function and Header File Functions
 
COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops
 
STRING FUNCTION - Programming in C.pptx
STRING FUNCTION -  Programming in C.pptxSTRING FUNCTION -  Programming in C.pptx
STRING FUNCTION - Programming in C.pptx
 
Diploma ii cfpc u-4 function, storage class and array and strings
Diploma ii  cfpc u-4 function, storage class and array and stringsDiploma ii  cfpc u-4 function, storage class and array and strings
Diploma ii cfpc u-4 function, storage class and array and strings
 
Unit 5 Foc
Unit 5 FocUnit 5 Foc
Unit 5 Foc
 
Mcai pic u 4 function, storage class and array and strings
Mcai pic u 4 function, storage class and array and stringsMcai pic u 4 function, storage class and array and strings
Mcai pic u 4 function, storage class and array and strings
 
VTU Data Structures Lab Manual
VTU Data Structures Lab ManualVTU Data Structures Lab Manual
VTU Data Structures Lab Manual
 
C file
C fileC file
C file
 
Btech i pic u-4 function, storage class and array and strings
Btech i pic u-4 function, storage class and array and stringsBtech i pic u-4 function, storage class and array and strings
Btech i pic u-4 function, storage class and array and strings
 
Functions torage class and array and strings-
Functions torage class and array and strings-Functions torage class and array and strings-
Functions torage class and array and strings-
 
function, storage class and array and strings
 function, storage class and array and strings function, storage class and array and strings
function, storage class and array and strings
 
3. chapter ii
3. chapter ii3. chapter ii
3. chapter ii
 
Variadic functions
Variadic functionsVariadic functions
Variadic functions
 
06 1 조건문
06 1 조건문06 1 조건문
06 1 조건문
 
Input output functions
Input output functionsInput output functions
Input output functions
 
An imperative study of c
An imperative study of cAn imperative study of c
An imperative study of c
 
C tutoria input outputl
C tutoria input outputlC tutoria input outputl
C tutoria input outputl
 
Bsc cs i pic u-4 function, storage class and array and strings
Bsc cs i pic u-4 function, storage class and array and stringsBsc cs i pic u-4 function, storage class and array and strings
Bsc cs i pic u-4 function, storage class and array and strings
 

Último

Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
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.pdfAdmir Softic
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...KokoStevan
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.MateoGardella
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 

Último (20)

Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
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
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 

Cd

  • 1. Program 5 WAP to count number of whitespaces and newline characters #include<stdio.h> #include<conio.h> #include<string.h> void main() { char str[200],ch; int a=0,space=0,newline=0; clrscr(); printf("n Enter a string(press escape to entering):"); ch=getche(); while((ch!=27)&&(a<199)) { str[a]=ch; if(str[a]==' ') { space++; } if(str[a]==13) { Seema 1136619815
  • 2. newline++; printf("n"); } a++; ch=getche(); } printf("n The number of lines used : %d",newline+1); printf("n The number of spaces used is : %d",space); getch(); } Seema 1136619815
  • 3. OUTPUT Seema 1136619815
  • 4. Program 6 WAP to implement the stack using array #include<stdio.h> #include<conio.h> # define MAXSIZE 10 void push(); int pop(); void traverse(); int stack[MAXSIZE]; int top=-1; void main() { int choice; char ch; do { clrscr(); printf("n1. PUSH"); printf("n2. POP"); printf("n3. TRAVERSE"); Seema 1136619815
  • 5. printf("n4. Enter your choice"); scanf("%d",&choice); switch(choice) { case 1: push(); break; case 2: printf("nThe deleted element is %d",pop()); break; case 3: traverse(); break; default: printf("nYou have entered wrong choice"); } printf("nDo you wish to continue(Y/N)"); fflush(stdin); scanf("%c",&ch); } while(ch=='Y'||ch=='N'); } void push() { int item; Seema 1136619815
  • 6. if(top==MAXSIZE-1) { printf("nThe stack is full"); getch(); exit(0); } else { printf("Enter the element to be inserted"); scanf("%d",&item); top=top+1; stack[top]=item; }} int pop() { int item; if(top==-1) { printf("The stack is empty"); getch(); exit(0); Seema 1136619815
  • 7. } else { item=stack[top]; top=top-1; } return(item); } void traverse() { int i; if(top==-1) { printf("The stack is empty"); getch(); exit(0); } else { for(i=top;i>=0;i--) { Seema 1136619815
  • 8. printf("nTraverse element is : "); printf("%d",stack[i]); }}} OUTPUT Seema 1136619815
  • 9. Program 7 WAP for computation of FIRST in grammer. #include<stdio.h> #include<conio.h> #include<string.h> void main() { char t[5],nt[10],p[5][5],first[5][5],temp; int i,j,not,nont,k=0,f=0; clrscr(); printf("n Enter the no. of Non-terminals in the grammer:"); scanf("%d",&nont); printf("n Enter the Non-terminals in the grammer:"); for(i=0;i<nont;i++) { scanf("n%c",&nt[i]); } printf("n Enter the no. of Terminals in the grammer:(Enter e for absiline)"); scanf("%d",&not); printf("n Enter the Terminals in the grammer:"); for(i=0;i<not||t[i]=='$';i++) Seema 1136619815
  • 10. { scanf("n%c",&t[i]); } for(i=0;i<nont;i++) { p[i][0]=nt[i]; first[i][0]=nt[i]; } printf("nEnter the productions :n"); for(i=0;i<nont;i++) { scanf("%c",&temp); printf("n Enter the production for %c(End the production with '$'sign):",p[i][0]); for(j=0;p[i][j]!='$';) { j+=1; scanf("%c",&p[i][j]); }} for(i=0;i<nont;i++) { printf("n The production for %c _>",p[i][0]); Seema 1136619815
  • 12. { first[i][j]=first[k][j] ; if(first[i][j]=='e') continue; first[i][j+1]='$'; f=1; break; }}}} for(i=0;i<nont;i++) { printf("nnThe first of %c->",first[i][0]); for(j=1;first[i][j]!='$';j++) { printf("%ct",first[i][j]); }} getch(); } Seema 1136619815
  • 13. OUTPUT Seema 1136619815
  • 14. Program 8 WAP to check whether the string is a keyword or not. #include<stdio.h> #include<conio.h> #include<string.h> void main() { int i,flag=0,m; char s[5][10]={"if","else","goto","continue","return"},st[10]; clrscr() ; printf("n Enter the string:"); gets(st); for(i=0;i<5;i++) { m=strcmp(st,s[i]); if(m==0) flag=1; } if(flag==0) printf("nit is not a keyword"); else printf("n it is a keyword"); getch(); } Seema 1136619815
  • 15. OUTPUT Seema 1136619815
  • 16. Program 9 Study of converting NFA from Regular Expression. Definition of Regular Expression A regular expression is another representation of a regular language, and is defined over an alphabet (defined as Σ). The simplest regular expressions are symbols from λ, ∅, and symbols from Σ. Regular expressions can be built from these simple regular expressions with parenthesis, in addition to union, Kleene star and concatenation operators. ( , ) are used to help define the order of operations * is the Kleene star + is the union operator ! is used to represent the empty string. NONDETERMINISTIC FINITE AUTOMATA (NFA) - Automata with the choice of two or more edges labeled with the same symbol or special edge labeled with ε, edges that may be taken without using a symbol. Example - the following NFA accepts either even number of a's or multiple of 3 a's; the NFA must correctly choose which path to follow at the first transition. An NFA is represented formally by a 5-tuple, (Q, Σ, Δ, q0, F), consisting of a finite set of states Q Seema 1136619815
  • 17. a finite set of input symbols Σ a transition relation Δ : Q × Σ → P(Q). an initial (or start) state q0 ∈ Q a set of states F distinguished as accepting (or final) states F ⊆ Q. Here, P(Q) denotes the power set of Q. CONVERTING A REGULAR EXPRESSION TO AN NFA Seema 1136619815
  • 18. Program 10 Study of Left Recursion. Definition "A grammar is left-recursive if we can find some non-terminal A which will eventually derive a sentential form with itself as the left-symbol. Immediate left recursion Immediate left recursion occurs in rules of the form where and are sequences of nonterminals and terminals, and doesn't start with . For example, the rule is immediately left-recursive. The recursive descent parser for this rule might look like: function Expr() { Expr(); match('+'); Term(); } and a recursive descent parser would fall into infinite recursion when trying to parse a grammar which contains this rule. Indirect left recursion Indirect left recursion in its simplest form could be defined as: possibly giving the derivation Seema 1136619815
  • 19. More generally, for the nonterminals , indirect left recursion can be defined as being of the form: where are sequences of nonterminals and terminals. Removing left recursion Removing immediate left recursion The general algorithm to remove immediate left recursion follows. Several improvements to this method have been made, including the ones described in "Removing Left Recursion from Context-Free Grammars", written by Robert C. Moore.[5] For each rule of the form where: A is a left-recursive nonterminal is a sequence of nonterminals and terminals that is not null ( ) is a sequence of nonterminals and terminals that does not start with A. replace the A-production by the production: And create a new nonterminal Seema 1136619815
  • 20. This newly created symbol is often called the "tail", or the "rest". As an example, consider the rule This could be rewritten to avoid left recursion as The last rule happens to be equivalent to the slightly shorter form Seema 1136619815