-
Notifications
You must be signed in to change notification settings - Fork 1
/
scanner.lex
50 lines (35 loc) · 856 Bytes
/
scanner.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
%option noyywrap
%{
#include "parser.h"
#include <stdio.h>
#include <string.h>
%}
WHITE [ \t]+
NAME [a-zA-Z_\*:&]+
STDHEADER <[a-zA-Z\.]+>
QSTRING \"([^"]*)\"
%%
PROGRAM return START;
END return END;
FILE return STARTFILE;
ENDFILE return ENDFILE;
MAIN return STARTMAIN;
ENDMAIN return ENDMAIN;
include return INCLUDE;
class return CLASS;
endclass return ENDCLASS;
"public:" return PUBLIC;
"private:" return PRIVATE;
const return CONST;
function return FUNCTION;
data return DATA;
"(" return LPAR;
")" return RPAR;
"," return COMMA;
{STDHEADER} { yylval.str_val = strdup(yytext); return STDHEADER; }
{QSTRING} { yylval.str_val = strdup(yytext); return QSTRING; }
{NAME} { yylval.str_val = strdup(yytext); return IDENTIFIER;}
{WHITE} ;
\n { yylineno++; }
. { printf("Unrecognized token%s!\n", yytext); exit(1); }
%%