Select Lines Starting with 'm' - Lex Program - Compiler Design

Program:

%{
%}
reg1 ^m.*\n

%%
{reg1} {ECHO;}
. ;
%%
Output:

( input file : c1.c

#include<stdio.h>
main ()
{
    int i,n,fact=1;
    printf("Enter the number: ");
    scanf("%d",&n);            //inputing the number
    for(i=1;i<=n;i++)        /* finding factorial */
    {
        fact = fact*i;
            }
    printf("Factorial=%d\n",fact);
}

)


nn@linuxmint ~ $ lex l7.lex
nn@linuxmint ~ $ gcc lex.yy.c -lfl
nn@linuxmint ~ $ ./a.out <c1.c

main ()











nn@linuxmint ~ $

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...