Lex specification program that generates a C program which takes a string “abcd" and generates pattern

Lex specification program that generates a C program which takes a string “abcd" and generates pattern

/*Write a Lex specification program that generates a C program which takes a string
“abcd” and prints the following output.
        abcd
        abc
        ab
        a
*/

%{ 
#include<stdio.h>
char i,j;
%}

%%
[a-z]* { for(i='d';i>=1;--i)
      {
           for(j='a';j<=i;++j)
           {
              printf("%c ",j);
           }
          printf("\n");
      }
}
%%

int main()
{
 yylex();
 return 0;
}

//output of this code


No comments:

Post a Comment

Featured post

Amazon Interview Process

On July 5, 1994, Jeff Bezos started the world's most "customer-centric" firm out of his garage in Bellevue, Washington. The A...