controller_load_parser.l 2.33 KB
Newer Older
Jeroen Vreeken's avatar
Jeroen Vreeken committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*
	Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2009
	Copyright Stichting C.A. Muller Radioastronomiestation, 2009

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.

 */

%option noinput
Jeroen Vreeken's avatar
Jeroen Vreeken committed
21
22
%option reentrant
%option bison-bridge
Jeroen Vreeken's avatar
Jeroen Vreeken committed
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

%{
#include <stdio.h>
#include <inttypes.h>
#include "controller_load_parser.tab.h"
#include "controller_load.h"

#undef YY_INPUT
#define YY_INPUT(buf,readbytes,sizebytes) controller_load_yy_input(buf,&readbytes,sizebytes)

%}

string		"\""[^"]*"\""

comment		"/*".*"*/"

number		[0-9]+
hexdigit	[0-9a-fA-F]

doublesimple	[+-]?{number}"."{number} 
doubleexp	[+-]?{number}"."?{number}?"e"[+-]*{number} 
double		{doublesimple}|{doubleexp}

int		[+-]?{number}+

unsignedlong	("0x"|"0X"){hexdigit}{5,}

floatcast	"("[ \t]*"float"[ \t]*")"
doublecast	"("[ \t]*"double"[ \t]*")"
intcast		"("[ \t]*"int"[ \t]*")"

%%

"{"		{ return BRACEOPENSYM; }
"}"		{ return BRACECLOSESYM; }
","		{ return COMMASYM; }

"frequency"	{ return FREQUENCYSYM; }
"blocks"	{ return BLOCKSSYM; }
"links"		{ return LINKSSYM; }
"traces"	{ return TRACESSYM; }
"params"	{ return PARAMSSYM; }

{floatcast} 	{ return FLOATCASTSYM; }
{doublecast} 	{ return DOUBLECASTSYM; }
{intcast}	{ return INTCASTSYM; }

{string}	{ 
Jeroen Vreeken's avatar
Jeroen Vreeken committed
71
72
			yylval->string = strdup(yytext + 1);
			yylval->string[strlen(yylval->string)-1] = 0;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
73
74
75
76
			return STRINGSYM;
		}

{double}	{
Jeroen Vreeken's avatar
Jeroen Vreeken committed
77
			sscanf(yytext, "%lg", &yylval->dbl);
Jeroen Vreeken's avatar
Jeroen Vreeken committed
78
79
80
81
			return DOUBLESYM;
		}

{unsignedlong}	{
Jeroen Vreeken's avatar
Jeroen Vreeken committed
82
			sscanf(yytext, "0x%lx", &yylval->ul);
Jeroen Vreeken's avatar
Jeroen Vreeken committed
83
84
85
86
			return UNSIGNEDLONGSYM;
		}

{int}		{
Jeroen Vreeken's avatar
Jeroen Vreeken committed
87
			yylval->integer = atoi(yytext);
Jeroen Vreeken's avatar
Jeroen Vreeken committed
88
89
90
			return INTSYM;
		}

Jeroen Vreeken's avatar
Jeroen Vreeken committed
91
92
"true"		{ yylval->integer = 1; return BOOLSYM; }
"false"		{ yylval->integer = 0; return BOOLSYM; }
Jeroen Vreeken's avatar
Jeroen Vreeken committed
93
94
95

[ \t\r]		/* skip */
{comment}	/* skip */
Jeroen Vreeken's avatar
Jeroen Vreeken committed
96
"\n"		{ yyset_lineno(yyget_lineno(yyscanner)+1, yyscanner);}
Jeroen Vreeken's avatar
Jeroen Vreeken committed
97
98
99

%%

Jeroen Vreeken's avatar
Jeroen Vreeken committed
100
int yywrap(yyscan_t scanner) { return 1; }