7. Lex specification program that generates a C program which takes a string “abcd” and prints the pattern

 

Lex specification program that generates a C program which takes a string “abcd” and prints the 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 ch;
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 the above program
Lex specification program that generates a C program which takes a string “abcd” and prints the pattern
Lex specification program that generates a C program which takes a string “abcd” and prints the pattern

Comments

Popular posts from this blog

Compiler Design

3. Lex program to find the length of the longest word

6. Lex program to count the number of words,small and capital letters, digits and special characters in a C file