~ubuntu-branches/ubuntu/oneiric/similarity-tester/oneiric

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
%{
/*	This file is part of the software similarity tester SIM.
	Written by Dick Grune, Vrije Universiteit, Amsterdam.
	$Id: javalang.l,v 1.6 2008/09/23 09:07:11 dick Exp $
*/

/*
	Java language front end for the similarity tester.
	Author:	Dick Grune <dick@cs.vu.nl>
*/

#include	"options.h"
#include	"algollike.h"
#include	"token.h"
#include	"idf.h"
#include	"lex.h"
#include	"lang.h"

/* Language-dependent Code */

static const struct idf reserved[] = {
	{"abstract",	NORM('a')},
	{"boolean",	NORM('b')},
	{"break",	NORM('B')},
	{"byte",	CTRL('B')},
	{"case",	NORM('c')},
	{"catch",	NORM('C')},
	{"char",	CTRL('C')},
	{"class",	META('c')},
	{"continue",	META('C')},
	{"default",	NORM('d')},
	{"do",		NORM('D')},
	{"double",	CTRL('D')},
	{"else",	NORM('e')},
	{"extends",	NORM('E')},
	{"false",	NORM('g')},	/* Boolean literal */
	{"final",	NORM('f')},
	{"finally",	NORM('F')},
	{"float",	CTRL('F')},
	{"for",		META('f')},
	{"if",		NORM('i')},
	{"implements",	NORM('I')},
	{"import",	CTRL('I')},
	{"instanceof",	META('i')},
	{"int",		META('I')},
	{"interface",	MTCT('I')},
	{"long",	NORM('l')},
	{"native",	NORM('n')},
	{"new",		NORM('N')},
	{"null",	CTRL('N')},	/* null literal */
	{"package",	NORM('p')},
	{"private",	NORM('P')},
	{"protected",	CTRL('P')},
	{"public",	META('p')},
	{"return",	NORM('r')},
	{"short",	NORM('s')},
	{"static",	NORM('S')},
	{"super",	CTRL('S')},
	{"switch",	META('s')},
	{"synchronized",META('S')},
	{"this",	NORM('t')},
	{"throw",	NORM('T')},
	{"throws",	CTRL('T')},
	{"true",	META('t')},	/* Boolean literal */
	{"void",	NORM('v')},
	{"volatile",	NORM('V')},
	{"while",	NORM('w')}
};

/* Special treatment of identifiers */

static TOKEN
idf2token(int hashing) {
	TOKEN tk;

	tk = idf_in_list(yytext, reserved, sizeof reserved, IDF);
	if (TOKEN_EQ(tk, IDF) && hashing) {
		/* return a one-token hash code */
		tk = idf_hashed(yytext);
	}
	return tk;
}

/* Token sets for module algollike */
const TOKEN NonFinals[] = {
	IDF,		/* identifier */
	NORM('{'),
	NORM('('),
	NORM('a'),	/* abstract */
	NORM('b'),	/* boolean */
	NORM('B'),	/* break */
	CTRL('B'),	/* byte */
	NORM('c'),	/* case */
	NORM('C'),	/* catch */
	CTRL('C'),	/* char */
	META('c'),	/* class */
	META('C'),	/* continue */
	NORM('d'),	/* default */
	NORM('D'),	/* do */
	CTRL('D'),	/* double */
	NORM('e'),	/* else */
	NORM('E'),	/* extends */
	NORM('f'),	/* final */
	NORM('F'),	/* finally */
	CTRL('F'),	/* float */
	META('f'),	/* for */
	NORM('i'),	/* if */
	NORM('I'),	/* implements */
	CTRL('I'),	/* import */
	META('i'),	/* instanceof */
	META('I'),	/* int */
	MTCT('I'),	/* interface */
	NORM('l'),	/* long */
	NORM('n'),	/* native */
	NORM('N'),	/* new */
	NORM('p'),	/* package */
	NORM('P'),	/* private */
	CTRL('P'),	/* protected */
	META('p'),	/* public */
	NORM('r'),	/* return */
	NORM('s'),	/* short */
	NORM('S'),	/* static */
	CTRL('S'),	/* super */
	META('s'),	/* switch */
	META('S'),	/* synchronized */
	NORM('T'),	/* throw */
	CTRL('T'),	/* throws */
	NORM('v'),	/* void */
	NORM('V'),	/* volatile */
	NORM('w'),	/* while */
	NOTOKEN
};
const TOKEN NonInitials[] = {
	NORM(')'),
	NORM('}'),
	NORM(';'),
	NOTOKEN
};
const TOKEN Openers[] = {
	NORM('{'),
	NORM('('),
	NORM('['),
	NOTOKEN
};
const TOKEN Closers[] = {
	NORM('}'),
	NORM(')'),
	NORM(']'),
	NOTOKEN
};

%}

%Start	Comment

Layout		([ \t\r\f])
ASCII95		([- !"#$%&'()*+,./0-9:;<=>?@A-Z\[\\\]^_`a-z{|}~])

Digit		([0-9a-fA-F])

UniCode		(\\u{Digit}{Digit}{Digit}{Digit})
AnyQuoted	((\\.)|{UniCode})
StrChar		([^"\n\\]|{AnyQuoted})
ChrChar		([^'\n\\]|{AnyQuoted})

StartComment	("/*")
EndComment	("*/")
SafeComChar	([^*\n])
UnsafeComChar	("*")

SingleLineCom	("//".*)

Idf		([A-Za-z][A-Za-z0-9_]*)

%%

{StartComment}	{
		/*	We do not have one single pattern to match a comment
			(although one can be written), for two reasons.
			The matched string might overflow lex-internal buffers
			like yysbuf and yytext; and the pattern would be very
			complicated and overtax lex.
			So we break up the string into safe chunks and keep
			track of where we are in a start condition <Comment>.
		*/
		BEGIN Comment;
	}

<Comment>{SafeComChar}+	{		/* safe comment chunk */
	}

<Comment>{UnsafeComChar}	{	/* unsafe char, read one by one */
	}

<Comment>"\n"		{		/* to break up long comments */
		return_eol();
	}

<Comment>{EndComment}	{		/* end-of-comment */
		BEGIN INITIAL;
	}

{SingleLineCom}"\n"	{		/* single-line comment */
		return_eol();
	}

\"{StrChar}*\"	{			/* strings */
		return_ch('"');
	}

\'{ChrChar}+\'	{			/* characters */
		return_ch('\'');
	}

(0x)?{Digit}+("l"|"L")?	{		/* numeral, passed as an identifier */
		return_tk(IDF);
	}

"import"{Layout}[^;]*;	{		/* import statement; ignore */
	}

{Idf}/"("	{			/* identifier in front of ( */
		TOKEN tk;

		tk = idf2token(option_set('F'));
		if (!TOKEN_EQ(tk, SKIP)) return_tk(tk);
	}

{Idf}	{				/* identifier */
		TOKEN tk;

		tk = idf2token(0 /* no hashing */);
		if (!TOKEN_EQ(tk, SKIP)) return_tk(tk);
	}

\;	{				/* semicolon, conditionally ignored */
		if (option_set('f')) return_ch(yytext[0]);
	}

\n	{				/* count newlines */
		return_eol();
	}

{Layout}	{			/* ignore layout */
	}

{ASCII95}	{			/* copy other text */
		return_ch(yytext[0]);
	}

.	{				/* count non-ASCII chars */
		lex_non_ascii_cnt++;
	}

%%

/* Language-INdependent Code */

void
yystart(void) {
	BEGIN INITIAL;
}

int
yywrap(void) {
	return 1;
}