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
| /*
lexer_java.l
(c) copyright Sylvester Hesp, 2002-2004
The contents of this file can be used freely, as long as this
copyright notice is put unchanged in every file where my code
appears
*/
%option noyywrap prefix="java"
%{
#include "lexer.h"
#include "html.h"
%}
ws [ \t]*
dig [0-9]
octdig [0-7]
hexdig [0-9A-Fa-f]
ident [A-Za-z_$][0-9A-Za-z_$]*
illegal [0-9]+[A-Za-z_$][0-9A-Za-z_$]*
long [Ll]
double [Dd]
float [Ff]
exp [Ee]
binexp [Pp]
hex [Xx]
int [+-]?(0|[1-9]{dig}*)({long}|{exp}[+-]?{dig}+)?
float1 [+-]?((0|[1-9]{dig}*)\.{dig}*|\.{dig}+)({exp}[+-]?{dig}+)?({double}|{float})?
float2 [+-]?(0|[1-9]{dig}*)({exp}[+-]?{dig}+)?({double}|{float})
hexnum [+-]?0{hex}{hexdig}+{long}?
hexfloat [+-]?0{hex}({hexdig}+(\.{hexdig}*)?|\.{hexdig}+){binexp}[+-]?{dig}+({double}|{float})?
octnum [+-]?0{octdig}+{long}?
number {int}|{float1}|{float2}|{hexfloat}|{hexnum}|{octnum}
rest [^A-Za-z_$0-9/*"'+-]+
keywords1 abstract|assert|default|if|private|this|boolean|do|implements|protected|throw
keywords2 break|double|import|public|throws|byte|else|enum|instanceof|return|transient
keywords3 case|extends|int|short|try|catch|final|interface|static|void|char|finally|long
keywords4 strictfp|volatile|class|float|native|super|while|const|for|new|switch|continue
keywords5 goto|package|synchronized|null|true|false
keyword {keywords1}|{keywords2}|{keywords3}|{keywords4}|{keywords5}
%%
"/*" eatuntil (this, "/*", "*/", TOKEN_COMMENT);
\/\/.* {
token (TOKEN_COMMENT, YYText (), 0, 1);
}
\" eatstring (this, '"', FLAG_ESCAPE_BACKSLASH, TOKEN_STRING);
' eatstring (this, '\'', FLAG_ESCAPE_BACKSLASH, TOKEN_STRING);
{number} {
token (TOKEN_NUMBER, YYText (), 0, 1);
}
{illegal} {
token (TOKEN_ERROR, YYText (), 0, 1);
}
{keyword}{ws}\( {
int len = strcspn (YYText (), " (");
token (TOKEN_KEYWORD, YYText (), len, 1);
yyless (len);
}
{keyword} {
token (TOKEN_KEYWORD, YYText (), 0, 1);
}
{ident}{ws}\( {
int len = strcspn (YYText (), " (");
token (TOKEN_METHOD, YYText (), len, 1);
yyless (len);
}
{ident} {
token (TOKEN_IDENT, YYText (), 0, 1);
}
{rest} {
token (TOKEN_NONE, YYText (), 0, 1);
}
.|\n {
token (TOKEN_NONE, YYText (), 0, 1);
}
%%
REGISTER_LEXER ("java"); |