Scanner.l
Go to the documentation of this file.
1%{
2
3// **********************************************************************
4//
5// Copyright (c) 2003-2017 ZeroC, Inc. All rights reserved.
6//
7// This copy of Ice is licensed to you under the terms described in the
8// ICE_LICENSE file included in this distribution.
9//
10// **********************************************************************
11
12#include <Ice/Ice.h>
13#include <IceStorm/Parser.h>
14#include <IceStorm/Grammar.h>
15
16#if defined(_MSC_VER) && defined(ICE_64)
17//
18// '=' : conversion from 'size_t' to 'int', possible loss of data
19// The result of fread() is a size_t and gets inserted into an int
20//
21# pragma warning( 4 : 4267 )
22//
23// 'initializing' : conversion from '__int64' to 'int', possible loss of data
24// Puts a pointer-difference into an int
25//
26# pragma warning( 4 : 4244 )
27#endif
28
29#if defined(_MSC_VER) && defined(ICE_32)
30//
31// '<' : signed/unsigned mismatch
32//
33# pragma warning( 4 : 4018 )
34#endif
35
36#if defined(__GNUC__)
37# pragma GCC diagnostic ignored "-Wsign-compare"
38#endif
39
40using namespace std;
41using namespace Ice;
42using namespace IceStorm;
43
44#ifdef _MSC_VER
45# ifdef yywrap
46# undef yywrap
47# define yywrap() 1
48# endif
49# define YY_NO_UNISTD_H
50#endif
51
52#ifdef __SUNPRO_CC
53# ifdef yywrap
54# undef yywrap
55# define yywrap() 1
56# endif
57# ifdef ICE_64
58# pragma error_messages(off,truncwarn)
59# endif
60#endif
61
62#define YY_INPUT(buf, result, maxSize) parser->getInput(buf, result, maxSize)
63
64namespace IceStorm
65{
66
67typedef std::map<std::string, int> StringTokenMap;
68static StringTokenMap keywordMap;
69
70void initScanner();
71
72}
73#define YY_USER_INIT initScanner();
74
std::map< std::string, int > StringTokenMap
Definition Scanner.cpp:489
void initScanner()
Definition Scanner.cpp:2062
75%}
76
77WS [ \t\v\f\r]
78NL [\n]
79keyword [[:alpha:]]*
80
81%option noyywrap
82%option always-interactive
83
84%%
85
86"//" {
87 // C++-style comment
88 int c;
89 do
90 {
91 c = yyinput();
92 }
93 while(c != '\n' && c != EOF);
94}
constexpr T c
95
96"/*" {
97 // C-style comment
98 while(true)
99 {
100 int c = yyinput();
101 if(c == '*')
102 {
103 int next = yyinput();
104 if(next == '/')
105 {
106 break;
107 }
108 else
109 {
110 unput(next);
111 }
112 }
113 else if(c == EOF)
114 {
115 parser->warning("EOF in comment");
116 break;
117 }
118 }
119}
#define unput(c)
Definition Scanner.cpp:185
Parser * parser
Definition Parser.cpp:34
120
121{WS}*(\\{WS}*{NL})? {
122 size_t len = strlen(yytext);
123 for(size_t i = 0; i < len; ++i)
124 {
125 if(yytext[i] == '\\')
126 {
127 parser->continueLine();
128 }
129 }
130}
char * yytext
Definition Scanner.cpp:421
131
132{NL}|; {
133 return ';';
134}
135
136\" {
137 // "..."-type strings
138 string s;
139 while(true)
140 {
141 char c = static_cast<char>(yyinput());
142 if(c == '"')
143 {
144 break;
145 }
146 else if(c == EOF)
147 {
148 parser->warning("EOF in string");
149 break;
150 }
151 else if(c == '\\')
152 {
153 char next = static_cast<char>(yyinput());
154 switch(next)
155 {
156 case '\\':
157 case '"':
158 {
159 s += next;
160 break;
161 }
162
163 default:
164 {
165 s += c;
166 unput(next);
167 }
168 }
169 }
170 else
171 {
172 s += c;
173 }
174 }
175 yylvalp->clear();
176 yylvalp->push_back(s);
177 return ICE_STORM_STRING;
178}
@ ICE_STORM_STRING
Definition Grammar.cpp:154
double s(double t, double s0, double v0, double a0, double j)
Definition CtrlUtil.h:33
179
180\' {
181 // '...'-type strings
182 string s;
183 while(true)
184 {
185 char c = static_cast<char>(yyinput());
186 if(c == '\'')
187 {
188 break;
189 }
190 else if(c == EOF)
191 {
192 parser->warning("EOF in string");
193 break;
194 }
195 else
196 {
197 s += c;
198 }
199 }
200 yylvalp->clear();
201 yylvalp->push_back(s);
202 return ICE_STORM_STRING;
203}
204
205. {
206 // Simple strings
207 string s;
208 s += yytext[0];
209 while(true)
210 {
211 char c = static_cast<char>(yyinput());
212 if(c == EOF)
213 {
214 break;
215 }
216 else if(isspace(static_cast<unsigned char>(c)) || c == ';')
217 {
218 unput(c);
219 break;
220 }
221
222 s += c;
223 }
224
225 yylvalp->clear();
226 yylvalp->push_back(s);
227
228 StringTokenMap::const_iterator pos = keywordMap.find(s);
229 return pos != keywordMap.end() ? pos->second : ICE_STORM_STRING;
230}
231
232%%
233
234namespace IceStorm {
235
236//
237// initScanner() fills the keyword map with all keyword-token pairs.
238//
239
240void
242{
243 keywordMap["help"] = ICE_STORM_HELP;
244 keywordMap["quit"] = ICE_STORM_EXIT;
245 keywordMap["exit"] = ICE_STORM_EXIT;
246 keywordMap["current"] = ICE_STORM_CURRENT;
247 keywordMap["create"] = ICE_STORM_CREATE;
248 keywordMap["destroy"] = ICE_STORM_DESTROY;
249 keywordMap["link"] = ICE_STORM_LINK;
250 keywordMap["unlink"] = ICE_STORM_UNLINK;
251 keywordMap["links"] = ICE_STORM_LINKS;
252 keywordMap["topics"] = ICE_STORM_TOPICS;
253 keywordMap["replica"] = ICE_STORM_REPLICA;
254 keywordMap["subscribers"] = ICE_STORM_SUBSCRIBERS;
255}
256
257}
@ ICE_STORM_SUBSCRIBERS
Definition Grammar.cpp:153
@ ICE_STORM_TOPICS
Definition Grammar.cpp:151
@ ICE_STORM_LINK
Definition Grammar.cpp:148
@ ICE_STORM_REPLICA
Definition Grammar.cpp:152
@ ICE_STORM_CURRENT
Definition Grammar.cpp:145
@ ICE_STORM_UNLINK
Definition Grammar.cpp:149
@ ICE_STORM_LINKS
Definition Grammar.cpp:150
@ ICE_STORM_EXIT
Definition Grammar.cpp:144
@ ICE_STORM_HELP
Definition Grammar.cpp:143
@ ICE_STORM_DESTROY
Definition Grammar.cpp:147
@ ICE_STORM_CREATE
Definition Grammar.cpp:146