2 * rpcgen - Generate XDR bindings automatically.
3 * Copyright (C) 2008 Red Hat Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "rpcgen_parse.h"
23 #include "rpcgen_int.h"
30 HEXLIT "0x"[0-9a-fA-F]+
33 INTLIT {HEXLIT}|{DECLIT}|{OCTLIT}
34 IDENT [a-zA-Z_][a-zA-Z_0-9]*
41 /* # lineno "filename"
42 * cpp itself sets file and line numbers using these directives. We
43 * have to parse this ourselves, since these could occur anywhere in
44 * the input, eg. in the middle of a struct definition.
50 /* Allocate enough space to store the returned filename string. */
51 filename = malloc (strlen (yytext));
52 if (filename == NULL) perrorf ("malloc");
54 if (sscanf (yytext+2, "%d \"%[^\"]\"", &lineno, filename) == 2) {
56 free (input_filename);
57 input_filename = filename;
62 /* Anything on a line beginning with % is passed to the output. Again
63 * we have to handle this within the scanner.
65 ^"%".*\n fputs (yytext+1, yyout);
67 /* C string constants. */
68 \" start_string(); BEGIN (cstring);
70 \" BEGIN (INITIAL); yylval.str = end_string(); return STRLIT;
72 \n error ("unterminated string constant");
73 <<EOF>> error ("unterminated string constant");
76 /* octal escape sequence */
79 (void) sscanf (yytext + 1, "%o", &result);
82 error ("octal constant is out of range");
87 /* Does C allow these?? Maybe confusing it with OCaml.
91 (void) sscanf( yytext + 1, "%x", &result );
97 /* generate error - bad escape sequence; something
98 * like '\48' or '\0777777'
100 error ("bad escape sequence: %s\n", yytext);
109 /* Backslash followed by a literal newline character. */
110 \\\n add_char ('\n');
112 /* Unrecognised escape character - should be an error? */
113 \\. add_char (yytext[1]);
121 struct return STRUCT;
124 typedef return TYPEDEF;
126 switch return SWITCH;
128 default return DEFAULT;
129 program return PROGRAM;
131 unsigned return UNSIGNED;
132 signed return SIGNED;
137 double return DOUBLE;
138 string return STRING;
139 opaque return OPAQUE;
145 {IDENT} { yylval.str = strdup (yytext); return IDENT; }
147 /* Numeric constants are tricky to scan accurately, so keep them as
148 * strings and pass them through directly to the C compiler.
150 {INTLIT} { yylval.str = strdup (yytext); return INTLIT; }
152 /* Single characters with special meaning. */
153 ":"|";"|","|"{"|"}"|"("|")"|"["|"]"|"<"|">"|"="|"*" return yytext[0];
155 /* Ignore whitespace. */
158 /* Anything else is an error. */
159 . error ("invalid character in input near '%c'", yytext[0]);