summaryrefslogtreecommitdiff
path: root/2003/i/buzz/src/config/config_lex.ll
blob: 31f980e03a3795d7c23dedf8e578cffa1304dcb0 (plain)
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
%{

#include "config_lex.h"

config_yytype config_yylval;

%}

ID	[_a-zA-Z][-_a-zA-Z0-9]*

NUM	[-+]?[0-9]+

HNUM	"0x"[0-9a-fzA-F]+

BNUM	"0b"[01]+

FLOAT	[-+]?[0-9]*"."[0-9]*

STRING	\"[^\n"]\"

%option noyywrap nounput
%option prefix="config_yy"

%%

{FLOAT}	{
    config_yylval.fl = strtod (config_yytext, 0);
    return FLOAT;
}

{BNUM}	{
    config_yylval.num = strtol (config_yytext + 2, 0, 2);
    return NUM;
}

{HNUM}	{
    config_yylval.num = strtol (config_yytext + 2, 0, 16);
    return NUM;
}

{NUM}	{
    config_yylval.num = strtol (config_yytext, 0, 10);
    return NUM;
}

"true"	{ config_yylval.boolean = true; return BOOL; }
"false"	{ config_yylval.boolean = false; return BOOL; }

{ID}        {
	config_yylval.id = config_yytext;
	return ID;
}

"#".*		/* Commentaires. */

[ \t\n]+	/* Rien � battre. */

.	return ERR;

%%

int
config_yyopen (const char *filename)
{
	config_yyin = fopen (filename, "r");
	if (!config_yyin) return -1;
	return 0;
}

void
config_yyclose (void)
{
	fclose (config_yyin);
}

// vim: ft=lex