2 * Copyright (C) 1999 the Free Software Foundation.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
28 static int parenth_depth = 0;
29 static int before_comment = INITIAL;
30 static int class_after_c = FALSE;
31 static int header_c = FALSE;
33 static GString *cbuf = NULL;
42 cbuf = g_string_new("");
44 cbuf = g_string_assign(cbuf,"");
52 cbuf = g_string_new(s);
54 cbuf = g_string_append(cbuf,s);
68 <*>\n { line_no++; REJECT; }
70 <*>MOTHERFUCKER { fprintf(stderr,"You are a bad bad person!\n"); REJECT; }
72 \/\/.*$ { ; /*comment, ignore*/ }
73 <C_CODE>\/\/.*$ { add_to_cbuf(yytext); /*comment, ignore*/ }
74 <CLASS_CODE>\/\/.*$ { ; /*comment, ignore*/ }
75 <CLASS_CODE_I>\/\/.*$ { ; /*comment, ignore*/ }
76 \/\* {BEGIN(COMMENT); before_comment = INITIAL; }
80 before_comment = C_CODE;
82 <CLASS_CODE>\/\* {BEGIN(COMMENT); before_comment = CLASS_CODE; }
83 <CLASS_CODE_I>\/\* {BEGIN(COMMENT); before_comment = CLASS_CODE_I; }
85 if(before_comment == C_CODE) add_to_cbuf(yytext);
86 BEGIN(before_comment);
90 if(before_comment == C_CODE) add_to_cbuf(yytext);
94 if(before_comment == C_CODE) add_to_cbuf(yytext);
100 class_after_c = FALSE;
103 ccode_line = line_no;
108 class_after_c = FALSE;
111 ccode_line = line_no;
123 <C_CODE>\'\{\' { add_to_cbuf(yytext); }
124 <C_CODE>\'\\\{\' { add_to_cbuf(yytext); }
125 <C_CODE>\'\}\' { add_to_cbuf(yytext); }
126 <C_CODE>\'\\\}\' { add_to_cbuf(yytext); }
127 <C_CODE>\'\"\' { add_to_cbuf(yytext); }
128 <C_CODE>\'\\\"\' { add_to_cbuf(yytext); }
130 <C_CODE>\\. { add_to_cbuf(yytext); }
132 BEGIN(C_CODE_STRING);
135 <C_CODE_STRING>\\. { add_to_cbuf(yytext); }
140 <C_CODE_STRING>. { add_to_cbuf(yytext); }
141 <C_CODE_STRING>\n { add_to_cbuf(yytext); }
149 if(parenth_depth<0) {
151 } else if(parenth_depth==0 && class_after_c) {
160 <C_CODE>. { add_to_cbuf(yytext); }
161 <C_CODE>\n { add_to_cbuf(yytext); }
168 <CLASS_CODE>from {return FROM;}
170 <CLASS_CODE_I>void {return VOID;}
171 <CLASS_CODE_I>struct {return STRUCT;}
172 <CLASS_CODE_I>union {return UNION;}
173 <CLASS_CODE_I>enum {return ENUM;}
174 <CLASS_CODE_I>signed {return SIGNED;}
175 <CLASS_CODE_I>unsigned {return UNSIGNED;}
176 <CLASS_CODE_I>long {return LONG;}
177 <CLASS_CODE_I>short {return SHORT;}
178 <CLASS_CODE_I>int {return INT;}
179 <CLASS_CODE_I>float {return FLOAT;}
180 <CLASS_CODE_I>double {return DOUBLE;}
181 <CLASS_CODE_I>char {return CHAR;}
182 <CLASS_CODE_I>const {return CONST;}
184 <CLASS_CODE_I>\.\.\. {return THREEDOTS;}
186 <CLASS_CODE_I>public {yylval.line = line_no; return PUBLIC;}
187 <CLASS_CODE_I>private {yylval.line = line_no; return PRIVATE;}
188 <CLASS_CODE_I>argument {yylval.line = line_no; return ARGUMENT;}
189 <CLASS_CODE_I>virtual {yylval.line = line_no; return VIRTUAL;}
190 <CLASS_CODE_I>signal {yylval.line = line_no; return SIGNAL;}
191 <CLASS_CODE_I>override {yylval.line = line_no; return OVERRIDE;}
192 <CLASS_CODE_I>onerror {return ONERROR;}
193 <CLASS_CODE_I>0|[1-9][0-9]*|0x[0-9a-fA-F]+|0[0-7]+|[0-9]*\.[0-9]+|\.[0-9][0-9]* {
194 yylval.id = g_strdup(yytext);
197 <CLASS_CODE,CLASS_CODE_I>:?[A-Za-z_][A-Za-z0-9_]*(:[A-Za-z0-9_]*)+ {
198 yylval.id = g_strdup(yytext);
201 <CLASS_CODE,CLASS_CODE_I>[A-Za-z_][A-Za-z0-9_]* {
202 yylval.id = g_strdup(yytext);
213 class_after_c = TRUE;
214 ccode_line = line_no;
215 yylval.line = line_no;
223 <CLASS_CODE,CLASS_CODE_I,INITIAL>[\t ] ; /*ignore*/
226 yylval.line = line_no;
230 <*>[\n\r] ; /*ignore*/