home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume12 / cake / part09 / Script / yygram < prev    next >
Encoding:
AWK Script  |  1987-10-15  |  377 b   |  29 lines

  1. #!/bin/awk -f
  2.  
  3. # extract the grammar from a yacc file 
  4. # usage yygram file ...
  5.  
  6. BEGIN    {
  7.         num = 0;
  8.         braces = 0;
  9.     }
  10. /^%%$/    {
  11.         braces++;
  12.         next;
  13.     }
  14. /JUNK/    {    exit;        }
  15. NF == 0    {    next;        }
  16. /\t;/    {    next;        }
  17.     {    
  18.         if (index($0, "{") > 0)
  19.             num++;
  20.         if (num == 0 && braces == 1)
  21.             print;
  22.         if (index($0, "}") > 0)
  23.             num--;
  24.     }    
  25. END    {
  26.         if (num != 0)
  27.             print "Unmatched braces";
  28.     }
  29.