-
Notifications
You must be signed in to change notification settings - Fork 7
/
simple.lex
55 lines (48 loc) · 885 Bytes
/
simple.lex
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
<?php # vim:ft=php
include 'jlex.php';
%%
%{
//<YYINITIAL> L? \" (\\.|[^\\\"])* \" { $this->createToken(CParser::TK_STRING_LITERAL); }
/* blah */
%}
%function nextToken
%line
%char
%state COMMENTS
ALPHA=[A-Za-z_]
DIGIT=[0-9]
ALPHA_NUMERIC={ALPHA}|{DIGIT}
IDENT={ALPHA}({ALPHA_NUMERIC})*
NUMBER=({DIGIT})+
WHITE_SPACE=([\ \n\r\t\f])+
%%
<YYINITIAL> {NUMBER} {
return $this->createToken();
}
<YYINITIAL> {WHITE_SPACE} { }
<YYINITIAL> "+" {
return $this->createToken();
}
<YYINITIAL> "-" {
return $this->createToken();
}
<YYINITIAL> "*" {
return $this->createToken();
}
<YYINITIAL> "/" {
return $this->createToken();
}
<YYINITIAL> ";" {
return $this->createToken();
}
<YYINITIAL> "//" {
$this->yybegin(self::COMMENTS);
}
<COMMENTS> [^\n] {
}
<COMMENTS> [\n] {
$this->yybegin(self::YYINITIAL);
}
<YYINITIAL> . {
throw new Exception("bah!");
}