Sharecodepoint popular queries

Saturday, 23 February 2019

Program to recognize and count the number of identifiers in a given input file. | Compiler Design Lab Programs


Compiler Design Lap Program :

%{
 #include<stdio.h>
 int id=0;
%}
%%
[a-zA-Z][a-zA-Z0-9_]* { id++ ; ECHO; printf(“\n”);}
.+ { ;}
\n { ;}
%%
int yywrap()
{
return 1;
}
main (int argc, char *argv[])
{
 if(argc!=2)
 {
 printf(“Usage: <./a.out> <sourcefile>\n”);
 exit(0);
 }
 yyin=fopen(argv[1],”r”);
 printf(“Valid identifires are\n”);
 yylex();
 printf(“No of identifiers = %d\n”,id);

0 comments:

Post a comment

 

Version 23.2.3.4 - 2016 - 2020 - © Sharecodepoint | Made in India. | Copyright Content | Facebook | Twitter | Instagram | Youtube