1 /* 2 * Copyright (c) 1987, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 static char sccsid[] = "@(#)yacc.c 8.1 (Berkeley) 06/06/93"; 10 #endif /* not lint */ 11 12 #include <stdio.h> 13 #include <string.h> 14 #include "ctags.h" 15 16 /* 17 * y_entries: 18 * find the yacc tags and put them in. 19 */ 20 y_entries() 21 { 22 register int c; 23 register char *sp; 24 register bool in_rule; 25 char tok[MAXTOKEN]; 26 27 while (GETC(!=,EOF)) 28 switch ((char)c) { 29 case '\n': 30 SETLINE; 31 /* FALLTHROUGH */ 32 case ' ': 33 case '\f': 34 case '\r': 35 case '\t': 36 break; 37 case '{': 38 if (skip_key((int)'}')) 39 in_rule = NO; 40 break; 41 case '\'': 42 case '"': 43 if (skip_key(c)) 44 in_rule = NO; 45 break; 46 case '%': 47 if (GETC(==,'%')) 48 return; 49 (void)ungetc(c,inf); 50 break; 51 case '/': 52 if (GETC(==,'*')) 53 skip_comment(); 54 else 55 (void)ungetc(c,inf); 56 break; 57 case '|': 58 case ';': 59 in_rule = NO; 60 break; 61 default: 62 if (in_rule || !isalpha(c) && c != (int)'.' 63 && c != (int)'_') 64 break; 65 sp = tok; 66 *sp++ = c; 67 while (GETC(!=,EOF) && (intoken(c) || c == (int)'.')) 68 *sp++ = c; 69 *sp = EOS; 70 getline(); /* may change before ':' */ 71 while (iswhite(c)) { 72 if (c == (int)'\n') 73 SETLINE; 74 if (GETC(==,EOF)) 75 return; 76 } 77 if (c == (int)':') { 78 pfnote(tok,lineno); 79 in_rule = YES; 80 } 81 else 82 (void)ungetc(c,inf); 83 } 84 } 85 86 /* 87 * toss_yysec -- 88 * throw away lines up to the next "\n%%\n" 89 */ 90 toss_yysec() 91 { 92 register int c, /* read character */ 93 state; 94 95 /* 96 * state == 0 : waiting 97 * state == 1 : received a newline 98 * state == 2 : received first % 99 * state == 3 : recieved second % 100 */ 101 lineftell = ftell(inf); 102 for (state = 0;GETC(!=,EOF);) 103 switch ((char)c) { 104 case '\n': 105 ++lineno; 106 lineftell = ftell(inf); 107 if (state == 3) /* done! */ 108 return; 109 state = 1; /* start over */ 110 break; 111 case '%': 112 if (state) /* if 1 or 2 */ 113 ++state; /* goto 3 */ 114 break; 115 default: 116 state = 0; /* reset */ 117 } 118 } 119