controller_load_parser.l 3.34 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
%}

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

41
42
43
44
45
variablename	[a-zA-Z\_][0-9a-zA-Z\-\_]*

doublevariable	"\$("{variablename}")"
stringvariable	"\${"{variablename}"}"

Jeroen Vreeken's avatar
Jeroen Vreeken committed
46
47
48
49
50
comment		"/*".*"*/"

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

51
52
doublesimple	{number}"."{number} 
doubleexp	{number}"."?{number}?"e"[+-]*{number} 
Jeroen Vreeken's avatar
Jeroen Vreeken committed
53
54
double		{doublesimple}|{doubleexp}

55
int		{number}+
Jeroen Vreeken's avatar
Jeroen Vreeken committed
56
57
58
59
60
61

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

floatcast	"("[ \t]*"float"[ \t]*")"
doublecast	"("[ \t]*"double"[ \t]*")"
intcast		"("[ \t]*"int"[ \t]*")"
Jeroen Vreeken's avatar
Jeroen Vreeken committed
62
boolcast	"("[ \t]*"bool"[ \t]*")"
Jeroen Vreeken's avatar
Jeroen Vreeken committed
63
64
65
66
67

%%

"{"		{ return BRACEOPENSYM; }
"}"		{ return BRACECLOSESYM; }
68
69
"("		{ return PARENTHESESOPENSYM; }
")"		{ return PARENTHESESCLOSESYM; }
Jeroen Vreeken's avatar
Jeroen Vreeken committed
70
","		{ return COMMASYM; }
71
72
73
74
"*"		{ return STARSYM; }
"/"		{ return SLASHSYM; }
"+"		{ return PLUSSYM; }
"-"		{ return MINSYM; }
Jeroen Vreeken's avatar
Jeroen Vreeken committed
75
76
77
78
79
80

"frequency"	{ return FREQUENCYSYM; }
"blocks"	{ return BLOCKSSYM; }
"links"		{ return LINKSSYM; }
"traces"	{ return TRACESSYM; }
"params"	{ return PARAMSSYM; }
81
"include"	{ return INCLUDESYM; }
82
"set"		{ return SETSYM; }
Jeroen Vreeken's avatar
Jeroen Vreeken committed
83

84
85
"deg2rad"	{ return FUNC_DEG2RAD_SYM; }
"rpm2rads"	{ return FUNC_RPM2RADS_SYM; }
86
"pi"		{ return CONST_PI_SYM; }
87

Jeroen Vreeken's avatar
Jeroen Vreeken committed
88
89
90
{floatcast} 	{ return FLOATCASTSYM; }
{doublecast} 	{ return DOUBLECASTSYM; }
{intcast}	{ return INTCASTSYM; }
Jeroen Vreeken's avatar
Jeroen Vreeken committed
91
{boolcast}	{ return BOOLCASTSYM; }
Jeroen Vreeken's avatar
Jeroen Vreeken committed
92

93
94
95
"true"		{ yylval->integer = 1; return BOOLSYM; }
"false"		{ yylval->integer = 0; return BOOLSYM; }

Jeroen Vreeken's avatar
Jeroen Vreeken committed
96
{string}	{ 
Jeroen Vreeken's avatar
Jeroen Vreeken committed
97
98
			yylval->string = strdup(yytext + 1);
			yylval->string[strlen(yylval->string)-1] = 0;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
99
100
101
			return STRINGSYM;
		}

102
103
104
105
106
107
108
109
110
111
112
113
114
{doublevariable}	{
			yylval->string = strdup(yytext + 2);
			yylval->string[strlen(yylval->string)-1] = 0;
			return DOUBLEVARIABLESYM;
		}

{stringvariable}	{
			yylval->string = strdup(yytext + 2);
			yylval->string[strlen(yylval->string)-1] = 0;
			return STRINGVARIABLESYM;
		}


Jeroen Vreeken's avatar
Jeroen Vreeken committed
115
{double}	{
Jeroen Vreeken's avatar
Jeroen Vreeken committed
116
			sscanf(yytext, "%lg", &yylval->dbl);
Jeroen Vreeken's avatar
Jeroen Vreeken committed
117
118
119
120
			return DOUBLESYM;
		}

{unsignedlong}	{
Jeroen Vreeken's avatar
Jeroen Vreeken committed
121
			sscanf(yytext, "0x%lx", &yylval->ul);
Jeroen Vreeken's avatar
Jeroen Vreeken committed
122
123
124
125
			return UNSIGNEDLONGSYM;
		}

{int}		{
Jeroen Vreeken's avatar
Jeroen Vreeken committed
126
			yylval->integer = atoi(yytext);
Jeroen Vreeken's avatar
Jeroen Vreeken committed
127
128
129
			return INTSYM;
		}

130
131
132
133
134
135
{variablename}	{
			yylval->string = strdup(yytext);
			return VARIABLENAMESYM;
		}


Jeroen Vreeken's avatar
Jeroen Vreeken committed
136
137

{comment}	/* skip */
Jeroen Vreeken's avatar
Jeroen Vreeken committed
138
[ \t\r]		/* skip */
Jeroen Vreeken's avatar
Jeroen Vreeken committed
139
140
#.*		/* skip */

Jeroen Vreeken's avatar
Jeroen Vreeken committed
141
"\n"		{ yyset_lineno(yyget_lineno(yyscanner)+1, yyscanner);}
Jeroen Vreeken's avatar
Jeroen Vreeken committed
142
143
144

%%

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