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

	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
%option nounput
Jeroen Vreeken's avatar
Jeroen Vreeken committed
24
25
26
27
28
29

%{
#include <stdio.h>
#include <inttypes.h>
#include "controller_load_parser.tab.h"
#include "controller_load.h"
30
#include "log.h"
Jeroen Vreeken's avatar
Jeroen Vreeken committed
31
32

#undef YY_INPUT
33
#define YY_INPUT(buf,readbytes,sizebytes) controller_load_yy_input(buf,&readbytes,sizebytes, yyscanner)
Jeroen Vreeken's avatar
Jeroen Vreeken committed
34

35
36
#define YY_FATAL_ERROR(msg) controller_load_fatal_error( msg , yyscanner)

Jeroen Vreeken's avatar
Jeroen Vreeken committed
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
%}

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]*")"
Jeroen Vreeken's avatar
Jeroen Vreeken committed
57
boolcast	"("[ \t]*"bool"[ \t]*")"
Jeroen Vreeken's avatar
Jeroen Vreeken committed
58
59
60
61
62
63
64
65
66
67
68
69

%%

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

"frequency"	{ return FREQUENCYSYM; }
"blocks"	{ return BLOCKSSYM; }
"links"		{ return LINKSSYM; }
"traces"	{ return TRACESSYM; }
"params"	{ return PARAMSSYM; }
70
"include"	{ return INCLUDESYM; }
Jeroen Vreeken's avatar
Jeroen Vreeken committed
71
72
73
74

{floatcast} 	{ return FLOATCASTSYM; }
{doublecast} 	{ return DOUBLECASTSYM; }
{intcast}	{ return INTCASTSYM; }
Jeroen Vreeken's avatar
Jeroen Vreeken committed
75
{boolcast}	{ return BOOLCASTSYM; }
Jeroen Vreeken's avatar
Jeroen Vreeken committed
76
77

{string}	{ 
Jeroen Vreeken's avatar
Jeroen Vreeken committed
78
79
			yylval->string = strdup(yytext + 1);
			yylval->string[strlen(yylval->string)-1] = 0;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
80
81
82
83
			return STRINGSYM;
		}

{double}	{
Jeroen Vreeken's avatar
Jeroen Vreeken committed
84
			sscanf(yytext, "%lg", &yylval->dbl);
Jeroen Vreeken's avatar
Jeroen Vreeken committed
85
86
87
88
			return DOUBLESYM;
		}

{unsignedlong}	{
Jeroen Vreeken's avatar
Jeroen Vreeken committed
89
			sscanf(yytext, "0x%lx", &yylval->ul);
Jeroen Vreeken's avatar
Jeroen Vreeken committed
90
91
92
93
			return UNSIGNEDLONGSYM;
		}

{int}		{
Jeroen Vreeken's avatar
Jeroen Vreeken committed
94
			yylval->integer = atoi(yytext);
Jeroen Vreeken's avatar
Jeroen Vreeken committed
95
96
97
			return INTSYM;
		}

Jeroen Vreeken's avatar
Jeroen Vreeken committed
98
99
"true"		{ yylval->integer = 1; return BOOLSYM; }
"false"		{ yylval->integer = 0; return BOOLSYM; }
Jeroen Vreeken's avatar
Jeroen Vreeken committed
100
101

{comment}	/* skip */
Jeroen Vreeken's avatar
Jeroen Vreeken committed
102
[ \t\r]		/* skip */
Jeroen Vreeken's avatar
Jeroen Vreeken committed
103
104
#.*		/* skip */

Jeroen Vreeken's avatar
Jeroen Vreeken committed
105
"\n"		{ yyset_lineno(yyget_lineno(yyscanner)+1, yyscanner);}
Jeroen Vreeken's avatar
Jeroen Vreeken committed
106
107
108

%%

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