SHARE
TWEET

Untitled

a guest Oct 21st, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. %{
  2. #include <stdio.h>
  3.  
  4. int yylex(void);
  5. void yyerror(char const *);
  6. %}
  7.  
  8. %token ZERO
  9. %token ONE
  10.  
  11. %%
  12. input: {printf("Enter the line:\n");}
  13.     | input line
  14.     ;
  15.  
  16. line: '\n' {printf("Empty line\n");}
  17.     | error '\n' {yyerrok;}
  18.     | exp3 '\n'
  19.     | exp4 '\n'
  20.     | exp3 exp1'\n'
  21.     | exp4 exp2'\n'
  22.     ;
  23.  
  24. exp1: ONE ONE
  25.     | exp1 ONE ONE
  26.     ;
  27.  
  28. exp2: ZERO ZERO
  29.     | exp2 ZERO ZERO
  30.     ;
  31.  
  32. exp3: exp1 exp2
  33.     | exp3 exp1 exp2
  34.     ;
  35.  
  36. exp4: exp2 exp1
  37.     | exp4 exp2 exp1
  38.     ;
  39.    
  40. %%
  41. int yylex(void)
  42. {
  43.     int c;
  44.     c=getchar();
  45.     if(c=='1')
  46.     return ONE;
  47.     if(c=='0')
  48.     return ZERO;
  49.     if (c==EOF)
  50.         return 0;    
  51.     return c;
  52. }
  53.  
  54. void yyerror(char const *s)
  55. {
  56.     fprintf(stderr, "%s\n", s);      
  57. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top