Fixed iSymCount problem, improved speed of search for lib functions,
[dyninst.git] / igen / src / scanner.l
1 %{
2 /*
3  * $Log $
4  *
5  */
6 #ifndef lint
7 static char Copyright[] =
8     "@(#) Copyright (c) 1992 Jeff Hollingsworth. All rights reserved.";
9
10 static char rcsid[] = "@(#) $Header: /home/jaw/CVSROOT_20081103/CVSROOT/core/igen/src/scanner.l,v 1.6 1994/06/02 23:34:29 markc Exp $";
11 #endif
12
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <string.h>
16
17 #define YYSTYPE union parseStack
18 #include "y.tab.h"
19 extern int generatePVM;
20 extern int generateXDR;
21 #include "parse.h"
22 #include "util/h/stringPool.h"
23
24 int parsing;
25 int cur_line = 1;
26 char cur_file[80];
27 extern int emitHeader;
28 extern stringPool pool;
29
30 int yylook();
31 int yyback(int*,int);
32
33 #ifdef notdef
34 #ifdef FLEX_SCANNER
35 /* flex defines this as a macro (bad flex!). */
36 #undef yywrap;
37 extern int yywrap();
38 #endif
39 #endif
40
41 extern void yyerror(char *);
42
43 int curr;
44 int len;
45 int lineNo = 0;
46 #define MAX 255
47 char line[MAX];
48 extern char *serverTypeName;
49
50 #undef getc
51 int getScanChar(FILE *file)
52 {
53     char *ret;
54
55     if (curr == len) {
56         ret = fgets(line, MAX, file);
57         if (!ret) return(EOF);
58         lineNo++;
59         len = strlen(line);
60         curr = 0;
61     }
62     return(line[curr++]);
63 }
64
65 #ifdef FLEX_SCANNER
66 #undef YY_INPUT
67 #define YY_INPUT(buf,result,max_size)   \
68 {                                       \
69     int c = getScanChar(yyin);          \
70     result = (c == EOF) ? YY_NULL : (buf[0] = c, 1); \
71 }
72 #endif
73
74 %}
75 DIGIT   [0-9]
76 DOLLAR  \$
77 INT     {DIGIT}+
78 FIX     {INT}"."{INT}
79 ALPHA   [A-Za-z]
80 IDENT   {ALPHA}({ALPHA}|{DIGIT}|_|".")*
81 %%
82 \$remote        { parsing = 1;  }
83 "//".*\n                { if (!parsing) REJECT; }
84 .*\n            { if (!parsing) {
85                     if (!strncmp(yytext, "$remote", strlen("$remote"))) {
86                         REJECT;
87                     } else {
88                         if (emitHeader) dump_to_dot_h(yytext);
89                     }
90                   } else {
91                     REJECT;
92                   }
93                 }
94 \$upcall        { return(tUPCALL); }
95 \$cmember       { return(tCMEMBER); }
96 \$smember       { return(tSMEMBER); }
97 \$virtual       { return(tVIRTUAL); }
98 \$base          { return(tBASE); }
99 \$name          { return(tNAME); }
100 \$version       { return(tVERSION); }
101 \$async         { return(tASYNC); }
102 \$array         { return(tARRAY); }
103 \$server        { yylval.cp = serverTypeName;
104                   return(tIDENT);
105                 }
106 "("             { return(tLPAREN); }
107 ")"             { return(tRPAREN); }
108 "{"             { return(tLBLOCK); }
109 "}"             { return(tRBLOCK); }
110 ","             { return(tCOMMA); }
111 "[]"            { return(tARRAY); }
112 "*"             { return(tSTAR); }
113 ";"             { /* parsing = 0; */
114                   return(tSEMI); 
115                 }
116 "typedef"       { return(tTYPEDEF); }
117 "struct"        { return(tSTRUCT); }
118 {IDENT}         { /* it's a identifier */
119                           char *temp;
120                   temp = (char *) malloc(strlen(yytext) + 1);
121                   strcpy(temp, yytext);
122                   yylval.cp = pool.findAndAdd(temp);
123                   return(tIDENT);
124                 }
125 [ \n\t]         { }
126 {INT}           {
127                   yylval.i = atoi(yytext);
128                   return(tINT);
129                 }
130
131 .               { yyerror("invalid character"); }
132 %%
133
134 void doString()
135 {
136     char ch;
137
138     while (1) {
139         ch = getScanChar(yyin);
140         switch (ch) {
141             case '"':
142                 yytext[yyleng] = '\0';
143                 return;
144                 break;
145             
146             case '\n':
147                 yyerror("Unterminated string literal");
148                 return;
149                 break;
150
151             default:
152                 yytext[yyleng] = ch;
153                 break;
154         }
155         yyleng++;
156     }
157 }
158
159 void yyerror(char *message)
160 {
161     int i;
162     fprintf(stderr, "line %d, col %d:%s\n", lineNo, curr, message);
163     fprintf(stderr, line);
164     for (i=0; i < curr; i++) {
165         fprintf(stderr, " ");
166     }
167     fprintf(stderr, "^\n");
168 }