source: trunk/athena/bin/cxref/cscan.l @ 6954

Revision 6954, 2.8 KB checked in by probe, 31 years ago (diff)
Initial revision
  • Property svn:executable set to *
Line 
1/*
2** cscan.l
3**
4** Does the major work of removing identifiers and constants
5** from the input stream, for Cxref. Its output is then extensively
6** postprocessed.
7**
8** Arnold Robbins, Information and Computer Science, Georgia Tech
9**      gatech!arnold
10** Copyright (c) 1984 by Arnold Robbins.
11** All rights reserved.
12** This program may not be sold, but may be distributed
13** provided this header is included.
14*/
15
16%{
17extern int line_no;
18extern char *fname, *basename();
19%}
20
21letter          [A-Za-z_]
22digit           [0-9]
23
24%%
25int             |
26char            |
27float           |
28double          |
29struct          |
30union           |
31long            |
32short           |
33unsigned        |
34auto            |
35extern          |
36register        |
37typedef         |
38static          |
39goto            |
40return          |
41sizeof          |
42break           |
43continue        |
44if              |
45else            |
46for             |
47do              |
48while           |
49switch          |
50case            |
51default         |
52entry           |
53enum            |
54void            |
55define          |
56undef           |
57include         |
58ifdef           |
59ifndef          |
60defined         |
61endif           ;       /* ignore C and cpp keywords */
62
63"<".+">"        ;       /* forget about include-file names */
64
65"\n"            line_no++;
66
67"/*"            {       /* get rid of comments */
68                        register char c, c1;
69
70                  loop: while((c = input()) != '*' && c != 0)
71                                if(c == '\n')
72                                        line_no++;
73
74                        if(c == 0)
75                        {
76                                fprintf(stderr,
77                                "unexpected EOF in comment at line %d, file %s\n",
78                                        line_no, basename(fname));
79                                exit(1);
80                        }
81
82                        if((c1 = input()) != '/')
83                        {
84                                unput(c1);      /* could be '*' before '/' */
85                                goto loop;
86                        }
87                }
88
89{letter}({letter}|{digit})*     outid();  /* what we actually want */
90
91'[^\\']'                |
92'\\{digit}{1,3}'        |
93'\\[\\bfrnlt']'                 outchar();
94
95\"                      {       /* collect quoted strings */
96                                register char c;
97                                register int i;
98
99                                for(i = 1, c = input(); ; i++, c = input())
100                                        switch (c) {
101                                        case '"':
102                                                yytext[i] = c;
103                                                yytext[++i] = '\0';
104                                                yyleng = i - 1;
105                                                goto fini;
106                                       
107                                        case '\\':
108                                                yytext[i] = '\\';
109                                                yytext[++i] = input();
110                                                if (yytext[i] == '\n')
111                                                {
112                                                        line_no++;
113                                                        yytext[i] = 'N';
114                                                        /* make visible */
115                                                }
116                                                break;
117
118                                        case 0:
119                                                fprintf(stderr,
120                                        "unexpected EOF inside string at line %d, file %s\n",
121                                                        line_no, basename(fname));
122                                                exit(1);
123                                                break;
124
125                                        default:
126                                                yytext[i] = c;
127                                                break;
128                                        }
129
130                                fini:
131                                        outstring();
132                }
133
134[+-]?{digit}+[lL]?                      |
135[+-]?0[Xx]({digit}|[a-fA-F])+[lL]?              outint();
136
137[+-]?{digit}*"."{digit}+([Ee][+-]?{digit}+)?    |
138[+-]?{digit}+"."{digit}*([Ee][+-]?{digit}+)?    |
139[+-]?{digit}+[Ee][+-]?{digit}+                          outfloat();
140
141.                       ;       /* delete everything else */
142
143%%
144
145yywrap()        /* wrap up for lex, return 1 */
146{
147        return(1);
148}
149
150#include "constdefs.h"
151
152extern char *fname;
153extern char *basename();
154
155outchar()
156{
157        outtext(CHAR);
158}
159
160outstring()
161{
162        outtext(STRING);
163}
164
165outint()
166{
167        int i = strlen(yytext);
168
169        /* handle long integer constants */
170
171        if (yytext[i-1] == 'l' || yytext[i-1] == 'L')
172                yytext[i-1] = '\0';
173
174        outtext(INT);
175}
176
177outfloat()
178{
179        outtext(FLOAT);
180}
181
182outtext(type)
183char type;
184{
185        printf("~%c%s\t%s\t%d\n", type, yytext, basename(fname), line_no);
186}
Note: See TracBrowser for help on using the repository browser.