1 /*
2  * This file is part of flex.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * Neither the name of the University nor the names of its contributors
15  * may be used to endorse or promote products derived from this software
16  * without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE.
22  */
23 
24 /* The point of this test is to be sure our M4 madness does not
25  * interfere with user code. I particular, we are looking
26  * for instances of M4 quotes, [[ and ]], in here to make it through the flex
27  * machinery unscathed.
28  */
29 
30 /* sect 1     [ 1 ]           TEST_XXX */
31 /* sect 1    [[ 2 ]]          TEST_XXX */
32 /* sect 1   [[[ 3 ]]]         TEST_XXX */
33 /* sect 1  [[[[ 4 ]]]]        TEST_XXX */
34 /* sect 1  ]] unmatched [[    TEST_XXX */
35 
36 %{
37 /* A template scanner file to build "scanner.c". */
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include "config.h"
41 /*#include "parser.h" */
42 
43 /* sect 1 block    [ 1 ]        TEST_XXX */
44 /* sect 1 block   [[ 2 ]]       TEST_XXX */
45 /* sect 1 block  [[[ 3 ]]]      TEST_XXX */
46 /* sect 1 block [[[[ 4 ]]]]     TEST_XXX */
47 /* sect 1 block ]] unmatched [[ TEST_XXX */
48 
49 static int a[1] = {0};
50 static int b[1] = {0};
51 static int c[1] = {0};
52 
foo(int i)53 static int foo (int i){
54     return a[b[c[i]]]; /* sect 1 code  TEST_XXX */
55 }
56 %}
57 
58 %option 8bit outfile="scanner.c" prefix="test"
59 %option nounput nomain noyywrap
60 %option warn
61 
62 
63 %%
64 
65 a       /* action comment    [ 1 ]          */ ;
66 b       /* action comment   [[ 2 ]]         */ ;
67 c       /* action comment  [[[ 3 ]]]        */ ;
68 d       /* action comment [[[[ 4 ]]]]       */ ;
69 e       /* action comment ]] unmatched [[   */ ;
70 f       return 1+foo(a[b[c[0]]]);
71 .|\n    {
72             /* action block    [ 1 ]        TEST_XXX */
73             /* action block   [[ 2 ]]       TEST_XXX */
74             /* action block  [[[ 3 ]]]      TEST_XXX */
75             /* action block [[[[ 4 ]]]]     TEST_XXX */
76             /* action block ]] unmatched [[ TEST_XXX */
77             return 1+foo(a[b[c[0]]]);  //   TEST_XXX
78          }
79 %%
80 
81 /* sect 3     [ 1 ]        TEST_XXX */
82 /* sect 3    [[ 2 ]]       TEST_XXX */
83 /* sect 3   [[[ 3 ]]]      TEST_XXX */
84 /* sect 3  [[[[ 4 ]]]]     TEST_XXX */
85 /* sect 3  ]] unmatched [[ TEST_XXX */
86 static int bar (int i){
87     return c[b[a[i]]]; /* sect 3 code TEST_XXX */
88 }
89 int main(void);
90 
91 int
main()92 main ()
93 {
94     yyin = stdin;
95     yyout = stdout;
96     while (yylex())
97         ;
98     printf("TEST RETURNING OK.\n");
99     return bar(0);
100 }
101 
102