void init_scanner char program continued cur line cur pos cur index yy

 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
void init_scanner(char *program)
{
continued =0;
cur.line = 1;
cur.pos =1;
cur.index = 0;
yy_scan_string(program);
}
void err(char *msg)
{
printf("Error ");
print_pos(&cur);
printf(": %s\n",msg);
}
%}
LETTER [a-zA-Z]
DIGIT [0-9]
IDENT {LETTER}({LETTER}|{DIGIT})*
NUMBER {DIGIT}+
%x COMMENTS CHAR_1 CHAR_2
%%
[\n\t ]+
\/\* BEGIN(COMMENTS); continued =1;
<COMMENTS> [~*]* continued =1;
<COMMENTS>\*\/ {
print_frag(yylloc);
printf(" comment\n");
BEGIN(0);
}
<COMMENTS>\* continued =1;
<COMMENTS><<EOF>> {
err("end of program found, '*/' expected");
return 0;
}