Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %{
- #include <stdio.h>
- int yylex(void);
- void yyerror(char const *);
- %}
- %token ZERO
- %token ONE
- %%
- input: {printf("Enter the line:\n");}
- | input line
- ;
- line: '\n' {printf("Empty line\n");}
- | error '\n' {yyerrok;}
- | exp3 '\n'
- | exp4 '\n'
- | exp3 exp1'\n'
- | exp4 exp2'\n'
- ;
- exp1: ONE ONE
- | exp1 ONE ONE
- ;
- exp2: ZERO ZERO
- | exp2 ZERO ZERO
- ;
- exp3: exp1 exp2
- | exp3 exp1 exp2
- ;
- exp4: exp2 exp1
- | exp4 exp2 exp1
- ;
- %%
- int yylex(void)
- {
- int c;
- c=getchar();
- if(c=='1')
- return ONE;
- if(c=='0')
- return ZERO;
- if (c==EOF)
- return 0;
- return c;
- }
- void yyerror(char const *s)
- {
- fprintf(stderr, "%s\n", s);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement