Write a grammar to accept the string that starts with 0,1 and the length of the string should be odd.

Lex file:

%{
#include "y.tab.h"
extern int yylval;
%}

%%
[0] yylval=atoi(yytext); return zero;
[1] yylval=atoi(yytext); return one;
[\t];
[\n] return 0;
%%
  

Yacc file:

%{
#include<stdio.h>
%}

%token zero one

%%
S : E {printf("String accepted");}
   :
E : E T T
    | T
    ;
T : zero
    | one
    ;
%%

main()
{
yyparse();
}
yyerror(char **arg)
{
printf("Invalid string");
}





Comments

Popular posts from this blog

A program to find FIRST of non-terminals of the given grammar

Write a context free grammar for structure of a english sentence, where a pronoun is followed by a verb and verb is followed by determiner. Determiner is followed by noun and noun can be followed by noun. Statement can begin with noun or a proper noun. **following program is written for example sentence"I prefer a morning flight from New Delhi".

Desk Calculator