steps to support modern FreeBSD. After Robert Watson <rwatson@FreeBSD.org> and Alec...
[arla.git] / ydr / lex.l
blobf2255d37a8679d9a5eb7b47bda1b6cc8b4c37a9f
1 %{
2 /*
3  * Copyright (c) 1995 - 2001 Kungliga Tekniska Högskolan
4  * (Royal Institute of Technology, Stockholm, Sweden).
5  * All rights reserved.
6  * 
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 
18  * 3. Neither the name of the Institute nor the names of its contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  * 
22  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  */
35 #ifdef HAVE_CONFIG_H
36 #include <config.h>
37 RCSID("$Id$");
38 #endif
41  * This is to handle the definition of this symbol in some AIX
42  * headers, which will conflict with the definition that lex will
43  * generate for it.  It's only a problem for AIX lex.
44  */
46 #ifndef __osf__
47 #undef ECHO
48 #endif
50 #include <stdio.h>
51 #include <ctype.h>
52 #include <stdarg.h>
53 #include <string.h>
54 #include <roken.h>
55 #include "sym.h"
56 #include "types.h"
57 #include "parse.h"
58 #include "lex.h"
59 #include "output.h"
61 #ifndef __osf__
62 #undef ECHO
63 #endif
65 #define YY_NO_UNPUT
67 static unsigned lineno;
69 static char filename[256];
71 static void parse_filename (char *s);
72 static void parse_lineno (char *s);
76 ^\#[ ][0-9]+[ ]\"[^\n\"]*\".*\n { parse_filename (yytext); }
77 ^\#line[ ][0-9]+[ ]\"[^\n\"]*\".*\n     { parse_filename (yytext); }
78 ^\#[ ][0-9]+.*\n                { parse_lineno (yytext); }
79 ^\#line[ ][0-9]+.*\n            { parse_lineno (yytext); }
80 ^\#ident.*$                     { }
81 ^\#pragma.*$                    { }
82 const                           { return T_CONST; }
83 enum                            { return T_ENUM; }
84 struct                          { return T_STRUCT; }
85 union                           { return T_UNION; }
86 switch                          { return T_SWITCH; }
87 case                            { return T_CASE; }
88 typedef                         { return T_TYPEDEF; }
89 unsigned                        { return T_UNSIGNED; }
90 long                            { return T_LONG; }
91 afs_int32                       { return T_LONG; }
92 int32_t                         { return T_LONG; }
93 afs_int64                       { return T_LONGLONG; }
94 int64_t                         { return T_LONGLONG; }
95 u_long                          { return T_ULONG; }
96 uint32_t                        { return T_ULONG; }
97 afs_uint32                      { return T_ULONG; }
98 uint64_t                        { return T_ULONGLONG; }
99 afs_uint64                      { return T_ULONGLONG; }
100 short                           { return T_SHORT; }
101 int16_t                         { return T_SHORT; }
102 u_short                         { return T_USHORT; }
103 uint16_t                        { return T_USHORT; }
104 int                             { return T_INT; }
105 u_char                          { return T_UCHAR; }
106 char                            { return T_CHAR; }
107 string                          { return T_STRING; }
108 opaque                          { return T_OPAQUE; }
109 package                         { return T_PACKAGE; }
110 prefix                          { return T_PREFIX; }
111 proc                            { return T_PROC; }
112 error-function                  { return T_ERROR_FUNCTION; }
113 split                           { return T_SPLIT; }
114 multi                           { return T_MULTI; }
115 IN                              { return T_IN; }
116 OUT                             { return T_OUT; }
117 INOUT                           { return T_INOUT; }
118 ASIS                            { return T_ASIS; }
119 "["|"]"|[,:;=()<>]|"{"|"}"|"*"  { return *yytext; }
120 ^\%[^\n]*$                      { yylval.name = strdup (yytext+1); return T_VERBATIM; }
121 -?[0-9]+                        { yylval.constant = atoi(yytext); return T_CONSTANT; }
122 0[Xx][0-9a-fA-F]+               { yylval.constant = (int)strtol(yytext+2, NULL, 0x10); return T_CONSTANT; }
123 [A-Za-z_][A-Za-z0-9_]*          {
124 Symbol *sym;
126 sym = findsym(yytext);
127 yylval.sym = sym;
128 if (sym == NULL) {
129     yylval.name = strdup(yytext);
130     return T_IDENTIFIER;
131 } else if (sym->type == YDR_TCONST)
132     return T_IDCONST;
133 else if (sym->type == YDR_TTYPEDEF
134          || sym->type == YDR_TENUM
135          || sym->type == YDR_TSTRUCT)
136     return T_IDTYPE;
137 else
138     error_message (0, "Ignoring \"%s\"\n", yytext);
140 [ \t]                           ;
141 \n                              { lineno++; }
142 .                               { error_message(0, "Ignoring char(%c)\n", *yytext); }
145 #ifndef yywrap
147 yywrap (void)
149      return 1;
151 #endif /* !yywrap */
153 void
154 error_message (int errorp, char *format, ...)
156      va_list args;
158      va_start (args, format);
159      fprintf (stderr, "%s:%d: ", filename, lineno);
160      vfprintf (stderr, format, args);
161      va_end (args);
162      if (errorp)
163          parse_errors = 1;
166 static void
167 parse_filename (char *s)
169      char *d1, *d2;
171      while (!isspace((unsigned char)*s))
172          ++s;
173      while (isspace((unsigned char)*s))
174          ++s;
176      lineno = atoi (s);
177      d1 = strchr (s, '"') + 1;
178      d2 = strchr (d1, '"');
179      *d2 = '\0';
180      if (strcmp (d1, "") != 0)
181          strlcpy (filename, d1, sizeof(filename));
184 static void
185 parse_lineno (char *s)
187      while (!isspace((unsigned char)*s))
188          ++s;
189      while (isspace((unsigned char)*s))
190          ++s;
192      lineno = atoi (s);