1 /******************************************************************************
2 * Copyright (c) 2000-2015 Ericsson Telecom AB
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 ******************************************************************************/
10 * Lexical analyzer for TTCN-3 character patterns.
12 * \author Matyas Forstner (Matyas.Forstner@eth.ericsson.se)
21 %option never-interactive
22 %option prefix="pattern_yy"
24 %{ /* ****************** C declarations ***************** */
29 #include "pattern_p.hh"
31 /* Access the semantic value of the bison parser. Usually this is done by
32 * #defining yylval to the appropriate symbol whose name depends on the
33 * %name-prefix of the parser, e.g. pattern_yylval or pattern_unilval.
35 * Because we need to be able to access either one or the other,
36 * we keep a pointer which is set by the parser when it calls
37 * init_pattern_yylex() */
38 static YYSTYPE *yylval_ptr;
39 #define yylval (*yylval_ptr)
41 static unsigned int nof_parentheses = 0;
42 static bool meta = false;
44 %} /* ***************** definitions ***************** */
46 NUMBER 0|([1-9][0-9]*)
48 /* start conditions */
49 %x SC_Set SC_Hash SC_HashParen SC_Quadruple SC_Quadruple_Set
51 %% /* ***************** rules ************************* */
53 /* drop whitespaces */
54 <SC_Hash,SC_HashParen,SC_Quadruple,SC_Quadruple_Set>[ \t\r\n\v\f]+
66 return KW_Set_Dash_End;
78 yylval.u = yytext[0] - '0';
89 <SC_HashParen,SC_Quadruple,SC_Quadruple_Set>
94 yylval.u = strtoul(yytext, NULL, 10);
95 if (errno != 0) TTCN_pattern_error("Number `%s' is too large to be "
96 "represented in memory. (%s)", yytext, strerror(errno));
102 } /* SC_HashParen,SC_Quadruple,SC_Quadruple_Set */
109 <SC_Quadruple,SC_Quadruple_Set>
115 if (YY_START == SC_Quadruple) BEGIN(INITIAL);
120 } /* SC_Quadruple,SC_Quadruple_Set */
122 "*" { meta = true; return '*'; }
123 "+" { meta = true; return '+'; }
124 "?" { meta = true; return '?'; }
125 "|" { meta = true; return '|'; }
130 return KW_Group_Begin;
134 if (nof_parentheses > 0) {
138 TTCN_pattern_error("Unmatched `)'.");
153 return KW_Set_Begin_Neg;
159 return KW_Set_Begin_Rsbrkt;
165 return KW_Set_Begin_Neg_Rsbrkt;
169 TTCN_pattern_error("Unmatched `]'.");
183 /* \metacharacters */
184 "\\d" { meta = true; return KW_BS_d; }
185 "\\w" { meta = true; return KW_BS_w; }
186 "\\t" { meta = true; return KW_BS_t; }
187 "\\n" { meta = true; return KW_BS_n; }
188 "\\r" { meta = true; return KW_BS_r; }
189 "\\s" { meta = true; return KW_BS_s; }
190 "\\b" { meta = true; return KW_BS_b; }
194 if (YY_START == INITIAL) BEGIN(SC_Quadruple);
195 else BEGIN(SC_Quadruple_Set);
199 /* escaped special characters: ? * \ [ ] - ^ | ( ) # + { } */
200 \\[][?*\\^|()#+{}-] {
201 yylval.c = yytext[1];
202 return TOK_Char; /* not meta */
205 /* invalid escape sequences */
207 if (isprint((unsigned char)yytext[1]))
208 TTCN_pattern_warning("Use of unrecognized escape sequence `\\%c' is "
209 "deprecated.", yytext[1]);
210 else TTCN_pattern_warning("Use of unrecognized escape sequence `\\' + "
211 "character code %u (0x%02X) is deprecated.", (unsigned char)yytext[1],
212 (unsigned char)yytext[1]);
213 yylval.c = yytext[1];
217 /* single backslash (at the end) */
219 TTCN_pattern_error("Invalid single backslash (`\\') character at the end "
224 yylval.c = yytext[0];
228 } /* INITIAL, SC_Set */
230 /* erroneous characters */
233 if (isprint((unsigned char)yytext[0]))
234 TTCN_pattern_error("A digit or `(' was expected after `#' instead of "
235 "character `%c'.", yytext[0]);
236 else TTCN_pattern_error("A digit or `(' was expected after `#' instead of "
237 "character with code %u (0x%02X).", (unsigned char)yytext[0],
238 (unsigned char)yytext[0]);
242 if (isprint((unsigned char)yytext[0]))
243 TTCN_pattern_error("A number, `,' or `)' was expected after `#(' instead "
244 "of character `%c'.", yytext[0]);
245 else TTCN_pattern_error("A number, `,' or `)' was expected after `#(' "
246 "instead of character with code %u (0x%02X).", (unsigned char)yytext[0],
247 (unsigned char)yytext[0]);
250 <SC_Quadruple,SC_Quadruple_Set>. {
251 if (isprint((unsigned char)yytext[0]))
252 TTCN_pattern_error("A number, `,' or `}' was expected after `\\q{' "
253 "instead of character `%c'.", yytext[0]);
254 else TTCN_pattern_error("A number, `,' or `}' was expected after `\\q{' "
255 "instead of character with code %u (0x%02X).", (unsigned char)yytext[0],
256 (unsigned char)yytext[0]);
261 unsigned int get_nof_parentheses()
263 return nof_parentheses;
271 void init_pattern_yylex(YYSTYPE *sema_val)
274 yylval_ptr = sema_val;