]>
Commit | Line | Data |
---|---|---|
82c035a8 AD |
1 | # Executing Actions. -*- Autotest -*- |
2 | # Copyright 2001 Free Software Foundation, Inc. | |
3 | ||
4 | # This program is free software; you can redistribute it and/or modify | |
5 | # it under the terms of the GNU General Public License as published by | |
6 | # the Free Software Foundation; either version 2, or (at your option) | |
7 | # any later version. | |
8 | ||
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. | |
13 | ||
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
17 | # 02111-1307, USA. | |
18 | ||
19 | AT_BANNER([[User Actions.]]) | |
20 | ||
21 | ## ------------------ ## | |
22 | ## Mid-rule actions. ## | |
23 | ## ------------------ ## | |
24 | ||
25 | AT_SETUP([Mid-rule actions]) | |
26 | ||
27 | # Bison once forgot the mid-rule actions. It was because the action | |
28 | # was attached to the host rule (the one with the mid-rule action), | |
29 | # instead of being attached to the empty rule dedicated to this | |
30 | # action. | |
31 | ||
32 | AT_DATA([[input.y]], | |
33 | [[%{ | |
34 | #include <stdio.h> | |
35 | #include <stdlib.h> | |
36 | static void yyerror (const char *msg); | |
37 | static int yylex (void); | |
38 | %} | |
39 | %% | |
40 | exp: { printf ("0\n"); } | |
41 | '1' { printf ("1\n"); } | |
42 | '2' { printf ("2\n"); } | |
43 | '3' { printf ("3\n"); } | |
44 | '4' { printf ("4\n"); } | |
45 | '5' { printf ("5\n"); } | |
46 | '6' { printf ("6\n"); } | |
47 | '7' { printf ("7\n"); } | |
48 | '8' { printf ("8\n"); } | |
49 | '9' { printf ("9\n"); } | |
50 | ; | |
51 | %% | |
52 | static int | |
53 | yylex (void) | |
54 | { | |
55 | static const char *input = "123456789"; | |
56 | return *input++; | |
57 | } | |
58 | ||
59 | static void | |
60 | yyerror (const char *msg) | |
61 | { | |
62 | fprintf (stderr, "%s\n", msg); | |
63 | } | |
64 | ||
65 | int | |
66 | main (void) | |
67 | { | |
68 | return yyparse (); | |
69 | } | |
70 | ]]) | |
71 | ||
72 | AT_CHECK([bison input.y -d -v -o input.c]) | |
73 | AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -o input], 0, [], [ignore]) | |
74 | AT_CHECK([input], 0, | |
75 | [[0 | |
76 | 1 | |
77 | 2 | |
78 | 3 | |
79 | 4 | |
80 | 5 | |
81 | 6 | |
82 | 7 | |
83 | 8 | |
84 | 9 | |
85 | ]]) | |
86 | ||
87 | AT_CLEANUP |