Lex Program to find the Syntax of Scanf()

Lex Program to find the Syntax of Scanf()

Source Code:-






1:  %{  

2:  #include<stdio.h>
3:  #include<ctype.h>
4:  int i=0,j=0;
5:  %}
6:  a "%d"|"%f"|"%c"|"%s"
7:  id [a-zA-Z][a-zA-Z0-9]*
8:  %%
9:  scanf\((\"({a}*|.*)*\"(,\&{id})*\))\; {for(i=0;i<yyleng;i++){if(yytext[i]=='%')
10:  j++;
11:  if(yytext[i]==',')
12:  j--;
13:  }
14:  if(j==0)
15:  printf("\ncorrect");  
16:  else  
17:  printf("incorrect");
18:  }
19:  %%
20:  main()
21:  { yyin=fopen("file13.c","r");
22:  yylex();
23:  }
24:  int yywrap()
25:  {return 1;
26:  }      

Comments

Popular posts from this blog

How To Install LEX and YACC in Linux or Ubuntu

Lex Program To Check The Syntax of For Loop

Listing/Delisting of an article in to an Assortment in SAP SCM Retail