1 /******************************************************************************
2 * Copyright (c) 2000-2016 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
15 * Szabo, Janos Zoltan – initial implementation
18 ******************************************************************************/
21 * Parser for TTCN-3 character patterns.
23 * \author Matyas Forstner (Matyas.Forstner@eth.ericsson.se)
30 /*********************************************************************
32 *********************************************************************/
37 #if defined(__CYGWIN__) && defined(__clang__)
38 /* Cygwin's clang 3.0 has its own limits.h, which does not bring in
39 the system's limits.h unless we define this macro: */
40 #define __STDC_HOSTED__ 1
41 #define _GCC_NEXT_LIMITS_H
46 #if !defined(RE_DUP_MAX)
47 /* RE_DUP_MAX is defined in limits.h or regex.h, except on Cygwin 1.5 */
48 # include <sys/syslimits.h>
54 /* defined in lexer c-file: */
57 extern int pattern_yylex();
58 extern void init_pattern_yylex(YYSTYPE *p);
59 struct yy_buffer_state;
60 extern yy_buffer_state* pattern_yy_scan_string(const char*);
61 extern int pattern_yylex_destroy();
62 extern unsigned int get_nof_parentheses();
64 /* defined in this file: */
66 /** The converted regexp. */
68 /** Turns error messages for extended ASCII characters on or off */
69 static bool allow_ext_ascii = false;
70 /** The parser error reporting function. */
71 static void pattern_yyerror(const char *error_str);
72 /** Creates the POSIX equivalent of literal character \a c using the
73 * appropriate escape sequence when needed. */
74 static char *translate_character(char c);
75 /** Returns the printable equivalent of character \a c */
76 static char *print_character(char c);
77 /** Returns the printable equivalent of range \a lower .. \a upper */
78 static char *print_range(char lower, char upper);
79 /** structure for manipulating character sets */
81 /** allocates, initializes and returns a new empty set */
82 static character_set *set_init();
83 /** allocates and returns a copy of \a set */
84 static character_set *set_copy(const character_set *set);
85 /** deallocates set \a set */
86 static void set_free(character_set *set);
87 /** returns whether set \a set is empty */
88 static int set_is_empty(const character_set *set);
89 /** returns whether set \a set contains all characters in range 1..127 */
90 static int set_is_full(const character_set *set);
91 /** returns whether set \a set contains the character \a c */
92 static int set_has_char(const character_set *set, char c);
93 /** adds character \a c to set \a set */
94 static void set_add_char(character_set *set, char c);
95 /** removes character \a c to set \a set */
96 static void set_remove_char(character_set *set, char c);
97 /** returns whether set \a set contains at least one character in the range
98 * \a lower .. \a upper */
99 static int set_has_range(const character_set *set, char lower, char upper);
100 /** adds range \a lower .. \a upper to set \a set */
101 static void set_add_range(character_set *set, char lower, char upper);
102 /** returns whether set \a set1 and \a set2 has non-empty intersect */
103 static int set_has_intersect(const character_set *set1,
104 const character_set *set2);
105 /** joins sets \a dst and \a src into \a dst */
106 static void set_join(character_set *dst, const character_set *src);
107 /** negates the set \a set */
108 static void set_negate(character_set *set);
109 /** reports the duplicate occurrences of characters and ranges in \a set1
111 static void set_report_duplicates(const character_set *set1,
112 const character_set *set2);
113 /** generates the POSIX equivalent of \a set */
114 static char *set_generate_posix(const character_set *set);
116 #define YYERROR_VERBOSE
118 static void yyprint(FILE *file, int type, const YYSTYPE& value);
119 #define YYPRINT(f,t,v) yyprint(f,t,v)
123 /*********************************************************************
125 *********************************************************************/
127 %name-prefix="pattern_yy"
128 %output="pattern_p.cc"
135 /*********************************************************************
137 * Must be kept in sync with the one in pattern_uni.y !
138 *********************************************************************/
142 char c; /* single character */
143 char *s; /* character string */
144 unsigned long int u; /* unsigned integer */
145 struct character_set *set; // used by nonterminals in pattern_p.y
149 #if defined(__sparc__) || defined(__sparc)
164 } q; // single universal char, used by nonterminals in pattern_uni.y
165 class QuadSet* qset; // used by nonterminals in pattern_uni.y
168 /*********************************************************************
170 *********************************************************************/
172 %token <c> TOK_Char "<ordinary character>"
173 %token <u> TOK_Number "<number>"
174 %token <u> TOK_Digit "<digit>"
176 /*********************************************************************
178 *********************************************************************/
189 %token KW_Group_Begin "("
190 %token KW_Group_End ")"
191 %token KW_Set_Begin "["
192 %token KW_Set_Begin_Neg "[^"
193 %token KW_Set_Begin_Rsbrkt "[]"
194 %token KW_Set_Begin_Neg_Rsbrkt "[^]"
195 %token KW_Set_End "]"
196 %token KW_Set_Dash_End "-]"
198 /*********************************************************************
199 * semantic types of nonterminals
200 *********************************************************************/
202 %type <b> RE_Set_Begin RE_Set_Begin_Rsbrkt RE_Set_End
203 %type <c> RE_Set_Range_Char RE_Quadruple
204 %type <s> RE_Body RE_Elems RE_Alter_Elem RE_Concat_Elem
205 RE_Multiply_Elem RE_Multiply_Statement RE_Group
207 %type <set> RE_Set RE_Set_Body RE_Set_Elem RE_Set_NoRange_Char
209 /*********************************************************************
211 *********************************************************************/
213 %destructor { Free($$); }
220 RE_Multiply_Statement
223 %destructor { set_free($$); }
231 /*********************************************************************
233 *********************************************************************/
236 RE_Body {ret_val=$1;}
247 $$ = mprintf("^%s$", $1);
249 } else $$ = mcopystr("^$");
254 RE_Alter_Elem { $$ = $1; }
255 | RE_Elems '|' RE_Alter_Elem
257 unsigned int nof_pars = get_nof_parentheses() + (yychar==KW_Group_End ? 1 : 0);
259 if ($1 != NULL) $$ = mputprintf($1, nof_pars ? "|%s" : "$|^%s", $3);
260 else $$ = mprintf( nof_pars ? "()|%s" : "()$|^%s" , $3);
263 if ($1 != NULL) $$ = mputstr($1, nof_pars ? "|()" : "$|^()");
270 RE_Concat_Elem { $$ = $1; }
271 | RE_Alter_Elem RE_Concat_Elem
273 $$ = mputstr($1, $2);
279 RE_Multiply_Elem {$$=$1;}
280 | RE_Multiply_Elem RE_Multiply_Statement
282 if ($1 != NULL && $2 != NULL) {
283 $$ = mputstr($1, $2);
291 | '*' {$$=mcopystr(".*");}
296 | RE_OneCharPos {$$=$1;}
300 KW_Group_Begin KW_Group_End
304 | KW_Group_Begin RE_Elems KW_Group_End
307 $$ = mprintf("(%s)", $2);
315 RE_Multiply_Statement:
327 TTCN_pattern_warning("The number of repetitions is zero: `#0'.");
329 } else if ($2 == 1) $$ = memptystr();
331 if ($2 > 9) TTCN_pattern_warning("Internal error: Invalid number of "
332 "repetitions: `#%lu'.", $2);
333 $$ = mprintf("{%lu}", $2);
336 | '#' '(' TOK_Number ')'
339 TTCN_pattern_warning("The number of repetitions is zero: `#(0)'.");
341 } else if ($3 == 1) $$ = memptystr();
344 if ($3 > RE_DUP_MAX) TTCN_pattern_warning("The number of repetitions in "
345 "`#(%lu)' exceeds the limit allowed by this system (%d).", $3,
348 $$ = mprintf("{%lu}", $3);
351 | '#' '(' TOK_Number ',' TOK_Number ')'
354 if ($3 > RE_DUP_MAX) TTCN_pattern_warning("The minimum number of "
355 "repetitions in `#(%lu,%lu)' exceeds the limit allowed by this system "
356 "(%d).", $3, $5, RE_DUP_MAX);
357 if ($5 > RE_DUP_MAX) TTCN_pattern_warning("The maximum number of "
358 "repetitions in `#(%lu,%lu)' exceeds the limit allowed by this system "
359 "(%d).", $3, $5, RE_DUP_MAX);
361 if ($3 > $5) TTCN_pattern_error("The lower bound is higher than the upper "
362 "bound in the number of repetitions: `#(%lu,%lu)'.", $3, $5);
365 TTCN_pattern_warning("The number of repetitions is zero: `#(0,0)'.");
367 } else if ($3 == 1) $$ = memptystr();
369 $$ = mprintf("{%lu}", $3);
372 if ($3 == 0 && $5 == 1) $$ = mcopystr("?");
373 else $$ = mprintf("{%lu,%lu}", $3, $5);
376 | '#' '(' ',' TOK_Number ')'
379 TTCN_pattern_warning("The number of repetitions is zero: `#(,0)'.");
383 if ($4 > RE_DUP_MAX) TTCN_pattern_warning("The maximum number of "
384 "repetitions in `#(,%lu)' exceeds the limit allowed by this system "
385 "(%d).", $4, RE_DUP_MAX);
387 if ($4 == 1) $$ = mcopystr("?");
388 else $$ = mprintf("{0,%lu}", $4);
391 | '#' '(' TOK_Number ',' ')'
393 if ($3 == 0) $$ = mcopystr("*");
396 if ($3 > RE_DUP_MAX) TTCN_pattern_warning("The minimum number of "
397 "repetitions in `#(%lu,)' exceeds the limit allowed by this system "
398 "(%d).", $3, RE_DUP_MAX);
400 if ($3 == 1) $$ = mcopystr("+");
401 else $$ = mprintf("{%lu,}", $3);
407 '?' {$$=mcopystr(".");}
408 | KW_BS_d {$$=mcopystr("[0-9]");}
409 | KW_BS_w {$$=mcopystr("[0-9A-Za-z]");}
410 | KW_BS_t {$$=mcopystr("\t");}
411 | KW_BS_n {$$=mcopystr("[\n-\r]");}
412 | KW_BS_r {$$=mcopystr("\r");}
413 | KW_BS_s {$$=mcopystr("[\t-\r ]");}
416 TTCN_pattern_warning("Metacharacter `\\b' is not supported yet.");
421 unsigned char c = $1;
422 if (c == 0 || (c > 127 && !allow_ext_ascii)) TTCN_pattern_error("Character "
423 "with code %u (0x%02x) cannot be used in a pattern for type charstring.", c, c);
424 $$ = translate_character($1);
428 $$ = translate_character($1);
432 if (set_is_empty($1)) {
433 TTCN_pattern_error("Empty character set.");
435 } else $$ = set_generate_posix($1);
441 /* RE_Set_Begin is 1 for "[^", 0 for "["
442 * RE_Set_Begin_Rsbrkt is 1 for "[^]", 0 for "[]"
443 * RE_Set_End is 1 for "-]", 0 for "]"
445 RE_Set_Begin RE_Set_Body RE_Set_End
447 if ($2 != NULL) $$ = $2;
448 else $$ = set_init();
450 if (set_has_char($$, '-'))
451 TTCN_pattern_warning("Duplicate character `-' in the character set.");
452 else set_add_char($$, '-');
454 if ($1) set_negate($$);
456 | RE_Set_Begin '-' RE_Set_Body RE_Set_End
458 if ($3 != NULL) $$ = $3;
459 else $$ = set_init();
460 if (set_has_char($$, '-'))
461 TTCN_pattern_warning("Duplicate character `-' in the character set.");
462 else set_add_char($$, '-');
464 if (set_has_char($$, '-'))
465 TTCN_pattern_warning("Duplicate character `-' in the character set.");
466 else set_add_char($$, '-');
468 if ($1) set_negate($$);
470 | RE_Set_Begin_Rsbrkt RE_Set_Body RE_Set_End
472 if ($2 != NULL) $$ = $2;
473 else $$ = set_init();
474 if (set_has_char($$, ']'))
475 TTCN_pattern_warning("Duplicate character `]' in the character set.");
476 else set_add_char($$, ']');
478 if (set_has_char($$, '-'))
479 TTCN_pattern_warning("Duplicate character `-' in the character set.");
480 else set_add_char($$, '-');
482 if ($1) set_negate($$);
484 | RE_Set_Begin_Rsbrkt '-' RE_Set_Range_Char RE_Set_Body RE_Set_End
486 if ($4 != NULL) $$ = $4;
487 else $$ = set_init();
488 char *range_str = print_range(']', $3);
490 TTCN_pattern_error("Invalid range `%s' in the character set: the "
491 "character code of the lower bound (%u) is higher than that of the "
492 "upper bound (%u).", range_str, ']', (unsigned char)$3);
494 if (set_has_range($$, ']', $3)) {
495 character_set *tmpset = set_init();
496 set_add_range(tmpset, ']', $3);
497 set_report_duplicates($$, tmpset);
501 set_add_range($$, ']', $3);
504 if (set_has_char($$, '-'))
505 TTCN_pattern_warning("Duplicate character `-' in the character set.");
506 else set_add_char($$, '-');
508 if ($1) set_negate($$);
513 KW_Set_Begin { $$ = 0; }
514 | KW_Set_Begin_Neg { $$ = 1; }
518 KW_Set_Begin_Rsbrkt { $$ = 0; }
519 | KW_Set_Begin_Neg_Rsbrkt { $$ = 1; }
523 KW_Set_End { $$ = 0; }
524 | KW_Set_Dash_End { $$ = 1; }
528 /* empty */ { $$ = NULL; }
529 | RE_Set_Body RE_Set_Elem
533 if (set_has_intersect($$, $2)) set_report_duplicates($$, $2);
544 set_add_char($$, $1);
546 | RE_Set_NoRange_Char { $$ = $1; }
547 | RE_Set_Range_Char '-' RE_Set_Range_Char
550 char *range_str = print_range($1, $3);
551 TTCN_pattern_error("Invalid range `%s' in the character set: the "
552 "character code of the lower bound (%u) is higher than that of the "
553 "upper bound (%u).", range_str, (unsigned char)$1, (unsigned char)$3);
557 set_add_range($$, $1, $3);
562 KW_BS_t { $$ = '\t'; }
563 | KW_BS_r { $$ = '\r'; }
566 unsigned char c = $1;
567 if (c == 0 || (c > 127 && !allow_ext_ascii)) TTCN_pattern_error("Character "
568 "with code %u (0x%02x) cannot be used in a pattern for type charstring.", c, c);
571 | RE_Quadruple { $$ = $1; }
578 set_add_range($$, '0', '9');
583 set_add_range($$, '0', '9');
584 set_add_range($$, 'A', 'Z');
585 set_add_range($$, 'a', 'z');
590 set_add_range($$, '\n', '\r');
595 set_add_range($$, '\t', '\r');
596 set_add_char($$, ' ');
600 TTCN_pattern_error("Metacharacter `\\b' does not make any sense in a "
607 KW_BS_q '{' TOK_Number ',' TOK_Number ',' TOK_Number ',' TOK_Number '}'
609 if ($3 > 127) TTCN_pattern_error("The first number (group) of quadruple "
610 "`\\q{%lu,%lu,%lu,%lu}' is too large. It should be in the range 0..127 "
611 "instead of %lu.", $3, $5, $7, $9, $3);
612 if ($5 > 255) TTCN_pattern_error("The second number (plane) of quadruple "
613 "`\\q{%lu,%lu,%lu,%lu}' is too large. It should be in the range 0..255 "
614 "instead of %lu.", $3, $5, $7, $9, $5);
615 if ($7 > 255) TTCN_pattern_error("The third number (row) of quadruple "
616 "`\\q{%lu,%lu,%lu,%lu}' is too large. It should be in the range 0..255 "
617 "instead of %lu.", $3, $5, $7, $9, $7);
618 if ($9 > 255) TTCN_pattern_error("The fourth number (cell) of quadruple "
619 "`\\q{%lu,%lu,%lu,%lu}' is too large. It should be in the range 0..255 "
620 "instead of %lu.", $3, $5, $7, $9, $9);
621 if ($3 > 0 || $5 > 0 || $7 > 0 || $9 > 127) TTCN_pattern_error("Quadruple "
622 "`\\q{%lu,%lu,%lu,%lu}' is not valid in a pattern for type charstring.",
624 if ($3 == 0 && $5 == 0 && $7 == 0 && $9 == 0) TTCN_pattern_error("Zero "
625 "character (i.e. quadruple `\\q{0,0,0,0}') is not supported in a "
626 "pattern for type charstring.");
633 /*********************************************************************
635 *********************************************************************/
637 char* TTCN_pattern_to_regexp(const char* p_pattern, bool utf8)
639 /* if you want to debug */
644 /* allow extended ASCII characters if the pattern is in UTF-8 format */
645 allow_ext_ascii = utf8;
647 yy_buffer_state *flex_buffer = pattern_yy_scan_string(p_pattern);
648 if(flex_buffer == NULL) {
649 TTCN_pattern_error("Flex buffer creation failed.");
652 init_pattern_yylex(&yylval);
653 if(pattern_yyparse()) {
657 pattern_yylex_destroy();
661 // Backwards compatibility shim
662 char* TTCN_pattern_to_regexp(const char* p_pattern, int ere)
664 TTCN_pattern_warning(
665 "TTCN_pattern_to_regexp(const char* p_pattern, int ere) is deprecated");
666 if (ere != 1) TTCN_pattern_error(
667 "BRE is not supported for TTCN_pattern_to_regexp");
668 return TTCN_pattern_to_regexp(p_pattern);
671 /*********************************************************************
673 *********************************************************************/
675 /// Error reporting function
676 void pattern_yyerror(const char *error_str)
678 TTCN_pattern_error("%s", error_str);
681 /** Escape plain characters which would be metacharacters in a regex.
683 * @param c plain character
684 * @return a newly allocated string which must be Free() 'd
686 char *translate_character(char c)
688 int escape_needed = 0;
706 if (escape_needed) return mprintf("\\%c", c);
707 else return mputc(NULL, c);
710 char *print_character(char c)
714 return mcopystr("\\t");
716 return mcopystr("\\r");
718 if (isprint((unsigned char)c)) return mprintf("%c", c);
719 else return mprintf("\\q{0,0,0,%u}", (unsigned char)c);
723 char *print_range(char lower, char upper)
725 char *range_str = print_character(lower);
726 range_str = mputc(range_str, '-');
727 char *upper_str = print_character(upper);
728 range_str = mputstr(range_str, upper_str);
733 #define CS_BITS_PER_ELEM (8 * sizeof(unsigned long))
734 #define CS_NOF_ELEMS ((128 + CS_BITS_PER_ELEM - 1) / CS_BITS_PER_ELEM)
736 struct character_set {
737 unsigned long set_members[CS_NOF_ELEMS];
740 character_set *set_init()
742 character_set *set = (character_set*)Malloc(sizeof(*set));
743 memset(set->set_members, 0, sizeof(set->set_members));
747 character_set *set_copy(const character_set *set)
749 character_set *set2 = (character_set*)Malloc(sizeof(*set2));
750 memcpy(set2, set, sizeof(*set2));
754 void set_free(character_set *set)
759 int set_is_empty(const character_set *set)
761 if ((set->set_members[0] & ~1UL) != 0) return 0;
762 for (size_t i = 1; i < CS_NOF_ELEMS; i++)
763 if (set->set_members[i] != 0) return 0;
767 int set_is_full(const character_set *set)
769 if (~(set->set_members[0] | 1UL) != 0) return 0;
770 for (size_t i = 1; i < CS_NOF_ELEMS; i++)
771 if (~set->set_members[i] != 0) return 0;
775 int set_has_char(const character_set *set, char c)
777 if (set->set_members[c / CS_BITS_PER_ELEM] & 1UL << c % CS_BITS_PER_ELEM)
782 void set_add_char(character_set *set, char c)
784 set->set_members[c / CS_BITS_PER_ELEM] |= 1UL << c % CS_BITS_PER_ELEM;
787 void set_remove_char(character_set *set, char c)
789 set->set_members[c / CS_BITS_PER_ELEM] &= ~(1UL << c % CS_BITS_PER_ELEM);
792 int set_has_range(const character_set *set, char lower, char upper)
794 for (size_t i = lower; i <= (unsigned char)upper; i++)
795 if (set->set_members[i / CS_BITS_PER_ELEM] & 1UL << i % CS_BITS_PER_ELEM)
800 void set_add_range(character_set *set, char lower, char upper)
802 for (size_t i = lower; i <= (unsigned char)upper; i++)
803 set->set_members[i / CS_BITS_PER_ELEM] |= 1UL << i % CS_BITS_PER_ELEM;
806 int set_has_intersect(const character_set *set1, const character_set *set2)
808 for (size_t i = 0; i < CS_NOF_ELEMS; i++)
809 if (set1->set_members[i] & set2->set_members[i]) return 1;
813 void set_join(character_set *dst, const character_set *src)
815 for (size_t i = 0; i < CS_NOF_ELEMS; i++)
816 dst->set_members[i] |= src->set_members[i];
819 void set_negate(character_set *set)
821 for (size_t i = 0; i < CS_NOF_ELEMS; i++)
822 set->set_members[i] = ~set->set_members[i];
825 void set_report_duplicates(const character_set *set1,
826 const character_set *set2)
828 for (unsigned char i = 0; i <= 127; ) {
829 for (i++; i <= 127; i++)
830 if (set_has_char(set2, i) && set_has_char(set1, i)) break;
833 for (i++; i <= 127; i++)
834 if (!set_has_char(set2, i) || !set_has_char(set1, i)) break;
837 char *range_str = print_range(lower, upper);
838 TTCN_pattern_warning("Duplicate range `%s' in the character set.",
842 char *char_str = print_character(lower);
844 TTCN_pattern_warning("Duplicate character `%s' in the character "
845 "set. Please note the \\n includes the \\r implicitly. "
846 "Use \\q{0,0,0,10} if you would like to match the LF only.", char_str);
848 TTCN_pattern_warning("Duplicate character `%s' in the character "
856 static char *append_posix_body(char *set_body, const character_set *set)
858 for (unsigned char i = 0; i <= 127; ) {
859 for (i++; i <= 127; i++) if (set_has_char(set, i)) break;
862 set_body = mputc(set_body, lower);
863 for (i++; i <= 127; i++) if (!set_has_char(set, i)) break;
866 if (lower + 1 < upper) set_body = mputc(set_body, '-');
867 set_body = mputc(set_body, upper);
873 static char *generate_posix_body(character_set *set)
876 if (set_has_char(set, '^') && !(set_has_char(set, '^' - 1) &&
877 set_has_char(set, '^' + 1))) {
878 set_remove_char(set, '^');
880 } else has_caret = 0;
882 if (set_has_char(set, '-') && !(set_has_char(set, '-' - 1) &&
883 set_has_char(set, '-' + 1))) {
884 set_remove_char(set, '-');
888 if (set_has_char(set, ']') && !(set_has_char(set, ']' - 1) &&
889 set_has_char(set, ']' + 1))) {
890 set_remove_char(set, ']');
892 } else has_rsbrkt = 0;
893 char *set_body = memptystr();
894 if (set_is_empty(set) && !has_rsbrkt) {
895 /* the `-' must precede the `^' */
896 if (has_dash) set_body = mputc(set_body, '-');
897 if (has_caret) set_body = mputc(set_body, '^');
899 /* order: ']', others, '^', '-' */
900 if (has_rsbrkt) set_body = mputc(set_body, ']');
901 set_body = append_posix_body(set_body, set);
902 if (has_caret) set_body = mputc(set_body, '^');
903 if (has_dash) set_body = mputc(set_body, '-');
908 static char *generate_posix_body_compl(character_set *set)
912 if (set_has_char(set, '-') && !(set_has_char(set, '-' - 1) &&
913 set_has_char(set, '-' + 1))) {
914 set_remove_char(set, '-');
918 if (set_has_char(set, ']') && !(set_has_char(set, ']' - 1) &&
919 set_has_char(set, ']' + 1))) {
920 set_remove_char(set, ']');
922 } else has_rsbrkt = 0;
923 char *set_body = mcopystr("^");
924 /* order: ']', others, '-' */
925 if (has_rsbrkt) set_body = mputc(set_body, ']');
926 set_body = append_posix_body(set_body, set);
927 if (has_dash) set_body = mputc(set_body, '-');
931 char *set_generate_posix(const character_set *set)
933 /* a full set can only be represented in this way: */
934 if (set_is_full(set)) return mcopystr(".");
935 character_set *tempset = set_copy(set);
936 char *set_body = generate_posix_body(tempset);
939 if (set_body[0] == '\0') {
941 TTCN_pattern_error("Internal error: empty POSIX set.");
944 /* do not use the set notation in POSIX if the set contains only one
946 if (set_body[1] == '\0') posix_str = translate_character(set_body[0]);
948 /* create the complemented version of the same set */
949 tempset = set_copy(set);
950 char *compl_body = generate_posix_body_compl(tempset);
952 if (compl_body[0] == '\0') {
955 TTCN_pattern_error("Internal error: empty complemented POSIX set.");
958 /* use the complemented form in the POSIX equivalent if it is the shorter
960 if (mstrlen(compl_body) < mstrlen(set_body))
961 posix_str = mprintf("[%s]", compl_body);
962 else posix_str = mprintf("[%s]", set_body);
969 void yyprint(FILE *file, int type, const YYSTYPE& value)
973 fprintf(file, "'%c'", value.c);
975 case TOK_Digit: case TOK_Number:
976 fprintf(file, "'%lu'", value.u);