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]+
32 INTLIT {HEXLIT}|{DECLIT}
33 IDENT [a-zA-Z_][a-zA-Z_0-9]*
40 /* # lineno "filename"
41 * cpp itself sets file and line numbers using these directives. We
42 * have to parse this ourselves, since these could occur anywhere in
43 * the input, eg. in the middle of a struct definition.
49 /* Allocate enough space to store the returned filename string. */
50 filename = malloc (strlen (yytext));
51 if (filename == NULL) perrorf ("malloc");
53 if (sscanf (yytext+2, "%d \"%[^\"]\"", &lineno, filename) == 2) {
54 yylineno = lineno - 1;
55 free (input_filename);
56 input_filename = filename;
61 /* Anything on a line beginning with % is passed to the output. Again
62 * we have to handle this within the scanner.
64 ^"%".*\n fputs (yytext+1, yyout);
66 /* C string constants. */
67 \" start_string(); BEGIN (cstring);
69 \" BEGIN (INITIAL); yylval.str = end_string(); return STRLIT;
71 \n error ("unterminated string constant");
72 <<EOF>> error ("unterminated string constant");
75 /* octal escape sequence */
78 (void) sscanf (yytext + 1, "%o", &result);
81 error ("octal constant is out of range");
86 /* Does C allow these?? Maybe confusing it with OCaml.
90 (void) sscanf( yytext + 1, "%x", &result );
96 /* generate error - bad escape sequence; something
97 * like '\48' or '\0777777'
99 error ("bad escape sequence: %s\n", yytext);
108 /* Backslash followed by a literal newline character. */
109 \\\n add_char ('\n');
111 /* Unrecognised escape character - should be an error? */
112 \\. add_char (yytext[1]);
120 struct return STRUCT;
123 typedef return TYPEDEF;
125 switch return SWITCH;
127 default return DEFAULT;
128 program return PROGRAM;
130 unsigned return UNSIGNED;
131 signed return SIGNED;
136 double return DOUBLE;
137 string return STRING;
138 opaque return OPAQUE;
143 {IDENT} { yylval.str = strdup (yytext); return IDENT; }
145 /* Numeric constants are tricky to scan accurately, so keep them as
146 * strings and pass them through directly to the C compiler.
148 {INTLIT} { yylval.str = strdup (yytext); return INTLIT; }
150 /* Single characters with special meaning. */
151 ":"|";"|","|"{"|"}"|"("|")"|"["|"]"|"<"|">"|"="|"*" return yytext[0];
153 /* Ignore whitespace. */
156 /* Anything else is an error. */
157 . error ("invalid character in input near '%c'", yytext[0]);