-
Notifications
You must be signed in to change notification settings - Fork 1
/
comment.flex
57 lines (45 loc) · 1.01 KB
/
comment.flex
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
%{
int line_num=0;
%}
%option noyywrap
DIGIT [0-9]+
CLASS (?i:class)
INHERITS (?i:inherits)
LET (?i:let)
IN (?i:in)
ASSIGN <-
NOTATION \:|,|\;|\{|\}|\(|\)
BLANK \f|\r|\ |\t|\v
NEWLINE \n
TYPE_IDENTFIER [A-Z][a-zA-Z0-9_]*
OBJ_IDENTFIER [a-z][a-zA-Z0-9_]*
%x comment_line
%x comment_all
%%
{DIGIT} printf("%s", yytext);
{CLASS} printf("%s", yytext);
{INHERITS} printf("%s", yytext);
{LET} printf("%s", yytext);
{IN} printf("%s", yytext);
{ASSIGN} printf("%s", yytext);
{NOTATION} printf("%s", yytext);
{BLANK} printf("%s", yytext);
{NEWLINE} line_num++;printf("%s", yytext);
{TYPE_IDENTFIER} printf("%s", yytext);
{OBJ_IDENTFIER} printf("%s", yytext);
-- BEGIN(comment_line);
<comment_line>[^\n]*
<comment_line>\n line_num++; BEGIN(INITIAL);
"(*" BEGIN(comment_all);
<comment_all>[^*\n]*
<comment_all>"*"+[^)\n]*
<comment_all>"*"+")" BEGIN(INITIAL);
<comment_all>\n line_num++;
.
%%
int main()
{
yyin = fopen("text", "r");
yylex();
printf("line_num=%d\n", line_num);
}