controller_load_parser.l 3.9 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

%{
#include <stdio.h>
#include <inttypes.h>
Jeroen Vreeken's avatar
Jeroen Vreeken committed
28
29
30
#include <controller/controller_load_parser.tab.h>
#include <controller/controller_load_int.h>
#include <log/log.h>
Jeroen Vreeken's avatar
Jeroen Vreeken committed
31
32

#undef YY_INPUT
Jeroen Vreeken's avatar
Jeroen Vreeken committed
33
34
35
36
37
#define YY_INPUT(buf,readbytes,sizebytes) do { \
	size_t rb = (readbytes); \
	controller_load_yy_input((buf),&rb,(sizebytes), (yyscanner)); \
	(readbytes) = rb; \
} while (0)
Jeroen Vreeken's avatar
Jeroen Vreeken committed
38

39
40
#define YY_FATAL_ERROR(msg) controller_load_fatal_error( msg , yyscanner)

Jeroen Vreeken's avatar
Jeroen Vreeken committed
41
42
43
44
%}

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

45
46
variablename	[a-zA-Z\_][0-9a-zA-Z\-\_]*

47
aliasvariable	"\$<"{variablename}">"
Jeroen Vreeken's avatar
Jeroen Vreeken committed
48
intvariable	"\$["{variablename}"]"
49
50
51
doublevariable	"\$("{variablename}")"
stringvariable	"\${"{variablename}"}"

Jeroen Vreeken's avatar
Jeroen Vreeken committed
52
53
54
55
56
comment		"/*".*"*/"

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

57
58
doublesimple	{number}"."{number} 
doubleexp	{number}"."?{number}?"e"[+-]*{number} 
Jeroen Vreeken's avatar
Jeroen Vreeken committed
59
60
double		{doublesimple}|{doubleexp}

61
int		{number}+
Jeroen Vreeken's avatar
Jeroen Vreeken committed
62
63
64
65
66
67

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

floatcast	"("[ \t]*"float"[ \t]*")"
doublecast	"("[ \t]*"double"[ \t]*")"
intcast		"("[ \t]*"int"[ \t]*")"
Jeroen Vreeken's avatar
Jeroen Vreeken committed
68
boolcast	"("[ \t]*"bool"[ \t]*")"
Jeroen Vreeken's avatar
Jeroen Vreeken committed
69
70
71
72
73

%%

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

82
"alias"		{ return ALIASSYM; }
83
"trigger"	{ return TRIGGERSYM; }
Jeroen Vreeken's avatar
Jeroen Vreeken committed
84
"blocks"	{ return BLOCKSSYM; }
Jeroen Vreeken's avatar
Jeroen Vreeken committed
85
"module"	{ return MODULESYM; }
Jeroen Vreeken's avatar
Jeroen Vreeken committed
86
87
88
"links"		{ return LINKSSYM; }
"traces"	{ return TRACESSYM; }
"params"	{ return PARAMSSYM; }
89
"include"	{ return INCLUDESYM; }
90
"import"	{ return IMPORTSYM; }
91
"set"		{ return SETSYM; }
Jeroen Vreeken's avatar
Jeroen Vreeken committed
92

93
94
"deg2rad"	{ return FUNC_DEG2RAD_SYM; }
"rpm2rads"	{ return FUNC_RPM2RADS_SYM; }
95
"pi"		{ return CONST_PI_SYM; }
96
"inf"		{ return CONST_INF_SYM; }
97

Jeroen Vreeken's avatar
Jeroen Vreeken committed
98
99
100
{floatcast} 	{ return FLOATCASTSYM; }
{doublecast} 	{ return DOUBLECASTSYM; }
{intcast}	{ return INTCASTSYM; }
Jeroen Vreeken's avatar
Jeroen Vreeken committed
101
{boolcast}	{ return BOOLCASTSYM; }
Jeroen Vreeken's avatar
Jeroen Vreeken committed
102

103
104
105
"true"		{ yylval->integer = 1; return BOOLSYM; }
"false"		{ yylval->integer = 0; return BOOLSYM; }

Jeroen Vreeken's avatar
Jeroen Vreeken committed
106
{string}	{ 
Jeroen Vreeken's avatar
Jeroen Vreeken committed
107
108
			yylval->string = strdup(yytext + 1);
			yylval->string[strlen(yylval->string)-1] = 0;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
109
110
111
			return STRINGSYM;
		}

112
113
114
115
116
117
{aliasvariable}	{
			yylval->string = strdup(yytext + 2);
			yylval->string[strlen(yylval->string)-1] = 0;
			return ALIASVARIABLESYM;
		}

Jeroen Vreeken's avatar
Jeroen Vreeken committed
118
119
120
121
122
123
{intvariable}	{
			yylval->string = strdup(yytext + 2);
			yylval->string[strlen(yylval->string)-1] = 0;
			return INTVARIABLESYM;
		}

124
125
126
127
128
129
130
131
132
133
134
135
136
{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
137
{double}	{
Jeroen Vreeken's avatar
Jeroen Vreeken committed
138
			sscanf(yytext, "%lg", &yylval->dbl);
Jeroen Vreeken's avatar
Jeroen Vreeken committed
139
140
141
142
			return DOUBLESYM;
		}

{unsignedlong}	{
Jeroen Vreeken's avatar
Jeroen Vreeken committed
143
			sscanf(yytext, "0x%lx", &yylval->ul);
Jeroen Vreeken's avatar
Jeroen Vreeken committed
144
145
146
147
			return UNSIGNEDLONGSYM;
		}

{int}		{
Jeroen Vreeken's avatar
Jeroen Vreeken committed
148
			yylval->integer = atoi(yytext);
Jeroen Vreeken's avatar
Jeroen Vreeken committed
149
150
151
			return INTSYM;
		}

152
153
154
155
156
157
{variablename}	{
			yylval->string = strdup(yytext);
			return VARIABLENAMESYM;
		}


Jeroen Vreeken's avatar
Jeroen Vreeken committed
158
159

{comment}	/* skip */
Jeroen Vreeken's avatar
Jeroen Vreeken committed
160
[ \t\r]		/* skip */
Jeroen Vreeken's avatar
Jeroen Vreeken committed
161
162
#.*		/* skip */

Jeroen Vreeken's avatar
Jeroen Vreeken committed
163
"\n"		{ yyset_lineno(yyget_lineno(yyscanner)+1, yyscanner);}
Jeroen Vreeken's avatar
Jeroen Vreeken committed
164
165
166

%%

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