System Software Lab 11 | Read Now
System Software VTU Lab
Program 11:- Program to recognize whether a given sentence is simple or compound.
Steps in writing LEX Program:
- Step – Using gedit create a file with extension .l For example: prg1.l
- Step – lex prg1.l
- Step – cc lex.yy.c –ll
- Step – ./a.out
Steps in writing YACC Program:
- Step: Using gedit editor create a file with extension y. For example: gedit prg1.y
- Step: YACC –d prg1.y
- Step: lex prg1.l
- Step: cc y.tab.c lex.yy.c -ll
- Step: /a.out
System Software Lab 11 Code [vi lab11.l]
%{
int flag=0;
%}
%%
" and " |
" or " |
" but " |
" because " |
" than "|
" nevertheless " {flag=1;}
%%
int main()
{
printf("Enter the sentence:\n");
yylex();
if(flag==1)
printf("compound statement");
else
printf("simple statements\n");
}
%{
int flag=0;
%}
%%
" and " |
" or " |
" but " |
" because " |
" than "|
" nevertheless " {flag=1;}
%%
int main()
{
printf("Enter the sentence:\n");
yylex();
if(flag==1)
printf("compound statement");
else
printf("simple statements\n");
}
%{ int flag=0; %} %% " and " | " or " | " but " | " because " | " than "| " nevertheless " {flag=1;} %% int main() { printf("Enter the sentence:\n"); yylex(); if(flag==1) printf("compound statement"); else printf("simple statements\n"); }
Output
