Skip to main content

Posts

Showing posts from October, 2017

No of comments lines in the c file and eliminate them and save into other file

%{ #include<stdio.h> int count=0; %} %% "/*"[^\n]+"*/" {count++;fprintf(yyout,"");} "//".* { count++; fprintf(yyout,"");} %% int main() { yyin=fopen("open.c","r"); yyout=fopen("new.c","w"); yylex(); printf("Number of Comments=%d\n",count);         return 0; } download the program file How to run this file 1. run lex file  using command " flex filename.l " 2.  it generate the  c file which can be execute by command " cc  lex.yy.c -ll " 3. it will generate the executable file " ./a.out "

lex program to count the number of fraction Positive and negative integer

/* decleration section in this sections we will decleared the different  value and include the header file which we are using in this program to run this program */ %{ #include<stdio.h> int pf_count=0; int nf_count=0; %} /* this sections is known as defined section in which we defined the rule and regulation of regular expression which will going to accept or not */ %% [+]?([0-9])+(\.([0-9])+)? { /* this is for fraction as eg: 2.03, +1 ,+0.3*/ pf_count++; printf("Positive fraction Integer:%s\n",yytext);} [-]([0-9])+(\.([0-9]+))?   { /* this will accept the negative fraction as eg: -3.3,-6 */ nf_count++; printf("Negative  fraction Integer:%s\n",yytext);} %% /* main function for calling the function */ void main(int argc[],char *argv[]) { yylex(); printf("the total number of Postive Integer are: %d\n" ,pf_count); printf("the total number of Negative  Integer are:%d\n",nf_count); }             ...

lex program to count the number of Positive and negative integer

/* decleration section in this sections we will decleared the different  value and include the header file which we are using in this program to run this program */ %{ #include<stdio.h> int p_count=0; int n_count=0; %} /* this sections is known as defined section in which we defined the rule and regulation of regular expression which will going to accept or not */ %% [+]?([0-9])+  { /* this is for increment and print the positive integer eg: 96, +36 */ p_count++; printf("Positive Integer:%s\n",yytext);} [-]([0-9])+   { /* this is for increment and print the negative integer eg: -96, -36 */ n_count++; printf("negative Integer:%s\n",yytext);} %% /* main function for calling the function */ void main(int argc[],char *argv[]) { yylex(); printf("the total number of Postive Integer are: %d\n" ,p_count); printf("the total number of Negative  Integer are:%d\n",n_count); }                ...

lex program for count character ,the word, space and new line in the given text file

/* deceleration section in this sections we will declared the different  value and include the header file which we are using in this program to run this program */ %{ #include<stdio.h> int nc_count=0;      // for count the character int nw_count=0;     // for count the word int ns_count=0;      // for count the space int nl_count=0;      // count the line %} /* this sections is known as defined section in which we defined the rule and regulation of regular expression which will going to accept or not */ %% [ ]  {ns_count++;nw_count++;} [\t]  {ns_count++;nw_count++;} [\n]  {nl_count++;nw_count++;} [a-zA-Z] {nc_count++;} %% /* main section for calling function */ int main() { FILE *fp; char file[10]; printf("enter the filename\n"); scanf("%s",file); fp=fopen(file,"r"); yyin=fp; yylex(); printf("character=%d\nword=%d\nSpace=%d\nLine=%d\n",nc_count,nw_count-1,ns_co...

count no of vowels and consonants

  To write a LEX program to count no of vowels and consonants in a given string. /* decleration section  */ %{#inlcude<stdio.h>  int v_count=0;  int c_count=0; %} /* definition section */ %% [aeiouAEIOU] {v_count++; }/*for vowels counting in the string*/ [a-zA-Z] {c_count++; }/* for consonants counting in the string*/ %% /* main section */ void main(int argc[],char *argv[]) { yylex(); printf("no of vowels in the string is:%d\n",v_count); printf("no of  consonants in the string is :%d\n",c_count); }                  download the program file

Compiler Design lab Program

  LEX Program  Q1. To write a LEX program to count no of vowels and consonants in a given string. Q2. To write a LEX program to count the numbers of characters, words, space and line in input file Q3. To write a LEX program to count the number of               a) Positive and negative integers               b) Positive fraction and negative fraction  Q4 . To write a LEX program to count the number of comment lines  in a given c file and eliminate them and copy that program into separate file Q5. To write a LEX to count the no of "scanf" and "printf"  statement in a c program. Replace them with "writf" and "readf" respectively. Q6. write a LEX program to identify the number is Even or Odd. YACC Program Q1. Write a YACC Program to check whether the arithmetic expression is valid or not? Q2. Write a YACC Program to evaluate the arithmetic expression and check valid...
Socket Programming using python Data Transport       There are two basic types of communications: Stream(TCP):    Computers establish a connection with each other and read/write data in a continuous stream bytes like a file.This is the most common. It is also provide reliable ,oriented connection service, control(flow and congestion).                                                                                                    Datagrams(UDP):    Userdatagram protocol, Computer send discrete packets to each other.Each packet contains a collection of bytes,but each packet is separate and self-contained. It is faster than TCP.   SOCKETS      ...