1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
|
%{
/*****************************************************************
Copyright (c) 1999 Torben Weis <[email protected]>
Copyright (c) 2000 Matthias Ettrich <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************************/
#define YY_NO_UNPUT
#include <stdlib.h>
#include <ctype.h>
class TQString;
#ifndef KDE_USE_FINAL
#include "yacc.cpp.h"
#endif
extern int idl_line_no;
int comment_mode;
int function_mode = 0;
#include <tqstring.h>
#include <tqregexp.h>
static long ascii_to_longlong( long base, const char *s )
{
long ll = 0;
while( *s != '\0' ) {
char c = *s++;
if( c >= 'a' )
c -= 'a' - 'A';
c -= '0';
if( c > 9 )
c -= 'A' - '0' - 10;
ll = ll * base + c;
}
return ll;
}
static double ascii_to_longdouble (const char *s)
{
double d;
#ifdef HAVE_SCANF_LF
sscanf (s, "%Lf", &d);
#else
/*
* this is only an approximation and will probably break fixed<>
* parameter calculation on systems where
* sizeof(double) < sizeof(long double). but fortunately all
* systems where scanf("%Lf") is known to be broken (Linux/Alpha
* and HPUX) have sizeof(double) == sizeof(long double).
*/
d = strtod (s, NULL);
#endif
return d;
}
static char translate_char( const char *s )
{
char c = *s++;
if( c != '\\' )
return c;
c = *s++;
switch( c ) {
case 'n':
return '\n';
case 't':
return '\t';
case 'v':
return '\v';
case 'b':
return '\b';
case 'r':
return '\r';
case 'f':
return '\f';
case 'a':
return '\a';
case '\\':
return '\\';
case '?':
return '\?';
case '\'':
return '\'';
case '"':
return '"';
case 'x':
case 'X':
return (char) ascii_to_longlong( 16, s );
default:
// Gotta be an octal
return (char) ascii_to_longlong( 8, s );
}
}
%}
%option noyywrap
%option never-interactive
/*--------------------------------------------------------------------------*/
Digits [0-9]+
Oct_Digit [0-7]
Hex_Digit [a-fA-F0-9]
Int_Literal [1-9][0-9]*L?
Oct_Literal 0{Oct_Digit}*
Hex_Literal (0x|0X){Hex_Digit}*
Esc_Sequence1 "\\"[ntvbrfa\\\?\'\"]
Esc_Sequence2 "\\"{Oct_Digit}{1,3}
Esc_Sequence3 "\\"(x|X){Hex_Digit}{1,2}
Esc_Sequence ({Esc_Sequence1}|{Esc_Sequence2}|{Esc_Sequence3})
Char ([^\n\t\"\'\\]|{Esc_Sequence})
Char_Literal "'"({Char}|\"|\\)"'"
String_Literal \"({Char}|"'")*\"
Float_Literal1 {Digits}"."{Digits}(e|E)("+"|"-")?{Digits}
Float_Literal2 {Digits}(e|E)("+"|"-")?{Digits}
Float_Literal3 {Digits}"."{Digits}
Float_Literal4 "."{Digits}
Float_Literal5 "."{Digits}(e|E)("+"|"-")?{Digits}
/*--------------------------------------------------------------------------*/
Kidl_Identifier [_a-zA-Z][a-zA-Z0-9_]*
/*--------------------------------------------------------------------------*/
%%
[ \t] ;
[\n] { idl_line_no++; }
"/\*" { comment_mode = 1; }
"\*/" { if (!comment_mode) { REJECT; } else { comment_mode = 0; } }
"}" {
if (! comment_mode) {
if (!function_mode) { REJECT; } else {
function_mode = 0;
return T_RIGHT_CURLY_BRACKET;
}
}
}
[^\n}*]* { if (!comment_mode && !function_mode) { REJECT; } }
"*" { if (!comment_mode) { REJECT; } }
"//"[^\n]* ;
"#!"[^\n]* {
exit( 1 );
}
"#include"[ \t]*[<\"][^>"]*[>\"]\s*\n {
TQString s( yytext );
int i = s.find(TQRegExp("[\"<]"))+1;
int j = s.find(TQRegExp("[\">]"), i);
yylval._str = new TQString( s.mid( i, j - i ) );
idl_line_no++;
return T_INCLUDE;
}
"#"[^\n]*\n {
idl_line_no++;
}
"{" return T_LEFT_CURLY_BRACKET;
"}" return T_RIGHT_CURLY_BRACKET;
"(" return T_LEFT_PARANTHESIS;
")" return T_RIGHT_PARANTHESIS;
":" return T_COLON;
"+" return T_PLUS;
"-" return T_MINUS;
"~" return T_TILDE;
"," return T_COMMA;
"*" return T_ASTERISK;
";" return T_SEMICOLON;
"&" return T_AMPERSAND;
"<" return T_LESS;
">" return T_GREATER;
"::" return T_SCOPE;
"=" return T_EQUAL;
"." return T_ACCESS;
"..." return T_TRIPLE_DOT;
"[" return T_ARRAY_OPEN;
"]" return T_ARRAY_CLOSE;
"->" return T_ACCESS;
(">>"|"<<") return T_SHIFT;
(">="|"<="|"!="|"==") return T_MISCOPERATOR;
const return T_CONST;
enum return T_ENUM;
namespace return T_NAMESPACE;
using return T_USING;
class return T_CLASS;
struct return T_STRUCT;
operator return T_FUNOPERATOR;
virtual return T_VIRTUAL;
public return T_PUBLIC;
inline return T_INLINE;
static return T_STATIC;
mutable return T_MUTABLE;
signed return T_SIGNED;
unsigned return T_UNSIGNED;
short return T_SHORT;
long return T_LONG;
friend return T_FRIEND;
protected return T_PROTECTED;
private return T_PRIVATE;
signals return T_SIGNAL;
return return T_RETURN;
slots return T_SLOT;
true return T_TRUE;
int return T_INT;
char return T_CHAR;
false return T_FALSE;
TRUE return T_TRUE;
FALSE return T_FALSE;
"k_dcop" return T_DCOP_AREA;
"k_dcop_signals" return T_DCOP_SIGNAL_AREA;
typedef return T_TYPEDEF;
K_DCOP return T_DCOP;
Q_OBJECT ;
TQ_OBJECT ;
("0"|"0L") return T_NULL;
"extern "[A-Za-z0-9_ \t*]+ return T_EXTERN;
"extern \"C\"" return T_EXTERN_C;
{Kidl_Identifier} {
yylval._str = new TQString( yytext );
return T_IDENTIFIER;
}
{Float_Literal1} |
{Float_Literal2} |
{Float_Literal3} |
{Float_Literal4} |
{Float_Literal5} {
yylval._float = ascii_to_longdouble( yytext );
return T_DOUBLE_LITERAL;
}
{Int_Literal} {
yylval._int = ascii_to_longlong( 10, yytext );
return T_INTEGER_LITERAL;
}
{Oct_Literal} {
yylval._int = ascii_to_longlong( 8, yytext );
return T_INTEGER_LITERAL;
}
{Hex_Literal} {
yylval._int = ascii_to_longlong( 16, yytext + 2 );
return T_INTEGER_LITERAL;
}
{Char_Literal} {
TQCString s( yytext );
s = s.mid( 1, s.length() - 2 );
yylval._char = translate_char( s );
return T_CHARACTER_LITERAL;
}
{String_Literal} {
TQString s( yytext );
yylval._str = new TQString( s.mid( 1, s.length() - 2 ) );
return T_STRING_LITERAL;
}
. {
if (function_mode)
return yylex(); // call once again
tqFatal("could not parse %c(%d) at line %d" , yytext[0], yytext[0], idl_line_no);
return T_UNKNOWN;
}
%%
void dcopidlInitFlex( const char *_code )
{
comment_mode = 0;
yy_switch_to_buffer( yy_scan_string( _code ) );
}
|