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

AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 

Último (20)

AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.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