3 # Fix up yacc output to allow dynamic allocation. Since perly.c
4 # is now provided with the perl source, this should not be necessary.
6 # However, if the user wishes to use byacc, or wishes to try another
7 # compiler compiler (e.g. bison or yacc), this script will get run.
8 # See makefile run_byacc target for more details.
10 # Currently, only byacc version 1.8 is fully supported.
12 # Hacks to make it work with Interactive's SysVr3 Version 2.2
13 # doughera@lafvax.lafayette.edu (Andy Dougherty) 3/23/91
15 # Additional information to make the BSD section work with SunOS 4.0.2
16 # tdinger@East.Sun.COM (Tom Dinger) 4/15/1991
18 # Also edit some practices gcc -Wall finds questionable.
25 inputh=`echo $input|sed 's:\.c$:.h:'`
26 if grep '^#ifdef PERL_CORE' $inputh; then
29 echo "#ifdef PERL_CORE" > $tmp
30 sed -e 's:^typedef union {:#endif /* PERL_CORE */\
32 typedef union {:' $inputh >> $tmp
36 if grep 'yaccpar 1.8 (Berkeley)' $input >/dev/null 2>&1; then
38 # Don't expect the diff to do everything -- do some by hand
39 if test -f perly_c.diff; then
40 patch -F3 $output <perly_c.diff
41 sed -e '/^[ ]*printf("yydebug:/s/printf(/PerlIO_printf(Perl_debug_log, /' \
42 -e '/^#line /s/"y[.]tab[.]c"/"perly.c"/' \
43 -e '/\[\] *= *[{]/s/^/static /' \
44 -e '/^static static/s/^static //' \
45 -e '/^#define.WORD/,/^#define.ARROW/d' \
46 -e '/^int.yydebug/,/^#define.yystacksize/d' \
47 -e 's/^yyerrlab:$//' \
48 -e 's/^ goto yyerrlab;//' \
49 -e 's/^yynewerror:$//' \
50 -e 's/^ goto yynewerror;//' \
51 -e 's|^static char yysccsid\(.*\)|/* static char yysccsid\1 */|' \
52 < $output > $tmp && mv -f $tmp $output || exit 1
54 echo "If you need to debug perly.c, you need to fix up the #line"
55 echo "directives yourself."
58 elif grep 'yaccpar 1.9 (Berkeley)' $input >/dev/null 2>&1; then
59 if test -f perly.c.dif9; then
60 patch -F3 $output <perly.c.dif9
61 sed -e '/^[ ]*printf("yydebug:/s/printf(/PerlIO_printf(Perl_debug_log, /' \
62 -e '/^#line /s/"y[.]tab[.]c"/"perly.c"/' \
63 -e '/\[\] *= *[{]/s/^/static /' \
64 -e '/^static static/s/^static //' \
65 -e '/^#define.WORD/,/^#define.ARROW/d' \
66 -e '/^int.yydebug/,/^#define.yystacksize/d' \
67 -e 's/^yyerrlab:$//' \
68 -e 's/^ goto yyerrlab;//' \
69 -e 's/^yynewerror:$//' \
70 -e 's/^ goto yynewerror;//' \
71 -e 's|^static char yysccsid\(.*\)|/* static char yysccsid\1 */|' \
72 < $output > $tmp && mv -f $tmp $output || exit 1
74 echo "If you need to debug perly.c, you need to fix up the #line"
75 echo "directives yourself."
78 echo "Diffs from byacc-1.9 are not available."
79 echo "If you wish to proceed anyway, do"
80 echo "cp $input $output"
81 echo "cp y.tab.h perly.h"
82 echo "and re-run make. Otherwise, I will use the old perly.c"
84 # Exit with error status to stop make.
92 echo "Warning: the yacc you have used is not directly supported by perl."
93 echo "The perly.fixer script will attempt to make some changes to the generated"
94 echo "file. The changes may be incomplete and that might lead to problems later"
95 echo "(especially with complex scripts). You may need to apply the changes"
96 echo "embedded in perl.fixer (and/or perly_c.dif*) by hand."
99 # Below, we check for various characteristic yaccpar outputs.
101 # Test for BSD 4.3 version.
102 # Also tests for the SunOS 4.0.2 version
103 egrep 'YYSTYPE[ ]*yyv\[ *YYMAXDEPTH *\];
104 short[ ]*yys\[ *YYMAXDEPTH *\] *;
105 yyps *= *&yys\[ *-1 *\];
106 yypv *= *&yyv\[ *-1 *\];
107 if *\( *\+\+yyps *>=* *&yys\[ *YYMAXDEPTH *\] *\)' $input >$tmp 2>/dev/null
110 if test "$1" = "5"; then
114 if test "$plan" = "unknown"; then
115 # Test for ISC 2.2 version (probably generic SysVr3).
116 egrep 'YYSTYPE[ ]*yyv\[ *YYMAXDEPTH *\];
117 int[ ]*yys\[ *YYMAXDEPTH *\] *;
118 yyps *= *&yys\[ *-1 *\];
119 yypv *= *&yyv\[ *-1 *\];
120 if *\( *\+\+yy_ps *>= *&yys\[ *YYMAXDEPTH *\] *\)' $input >$tmp 2>/dev/null
123 if test "$1" = "5"; then
131 ##################################################################
132 # The SunOS 4.0.2 version has the comparison fixed already.
133 # Also added are out of memory checks (makes porting the generated
134 # code easier) For most systems, it can't hurt. -- TD
136 echo "Attempting to patch perly.c to allow dynamic yacc stack allocation"
137 echo "Assuming bsd4.3 yaccpar"
139 /YYSTYPE[ ]*yyv\[ *YYMAXDEPTH *\];/c\
140 int yymaxdepth = YYMAXDEPTH;\
141 YYSTYPE *yyv; /* where the values are stored */\
145 /short[ ]*yys\[ *YYMAXDEPTH *\] *;/d
147 /yyps *= *&yys\[ *-1 *\];/d
149 /yypv *= *&yyv\[ *-1 *\];/c\
151 \ New(73, yyv, yymaxdepth, YYSTYPE);\
152 \ New(73, yys, yymaxdepth, short);\
153 \ if ( !yyv || !yys ) {\
154 \ yyerror( "out of memory" );\
157 \ maxyyps = &yys[yymaxdepth];\
163 /if *( *\+\+yyps *>=* *&yys\[ *YYMAXDEPTH *\] *)/c\
164 \ if( ++yyps >= maxyyps ) {\
165 \ int tv = yypv - yyv;\
166 \ int ts = yyps - yys;\
169 \ Renew(yyv, yymaxdepth, YYSTYPE);\
170 \ Renew(yys, yymaxdepth, short);\
171 \ if ( !yyv || !yys ) {\
172 \ yyerror( "yacc stack overflow" );\
177 \ maxyyps = &yys[yymaxdepth];\
180 /yacc stack overflow.*}/d
181 /yacc stack overflow/,/}/d
183 if sed -f $tmp <$input >$output
184 then echo "The edit seems to have been applied okay."
185 else echo "The edit seems to have failed!"
189 #######################################################
190 "isc") # Interactive Systems 2.2 version
191 echo "Attempting to patch perly.c to allow dynamic yacc stack allocation"
192 echo "Assuming Interactive SysVr3 2.2 yaccpar"
193 # Easier to simply put whole script here than to modify the
194 # bsd script with sed.
195 # Main changes: yaccpar sometimes uses yy_ps and yy_pv
196 # which are local register variables.
197 # if(++yyps > YYMAXDEPTH) had opening brace on next line.
198 # I've kept that brace in along with a call to yyerror if
199 # realloc fails. (Actually, I just don't know how to do
200 # multi-line matches in sed.)
202 /YYSTYPE[ ]*yyv\[ *YYMAXDEPTH *\];/c\
203 int yymaxdepth = YYMAXDEPTH;\
204 YYSTYPE *yyv; /* where the values are stored */\
208 /int[ ]*yys\[ *YYMAXDEPTH *\] *;/d
210 /yyps *= *&yys\[ *-1 *\];/d
212 /yypv *= *&yyv\[ *-1 *\];/c\
214 \ New(73, yyv, yymaxdepth, YYSTYPE);\
215 \ New(73, yys, yymaxdepth, int);\
216 \ maxyyps = &yys[yymaxdepth];\
221 /if *( *\+\+yy_ps *>= *&yys\[ *YYMAXDEPTH *\] *)/c\
222 \ if( ++yy_ps >= maxyyps ) {\
223 \ int tv = yy_pv - yyv;\
224 \ int ts = yy_ps - yys;\
227 \ Renew(yyv, yymaxdepth, YYSTYPE);\
228 \ Renew(yys, yymaxdepth, int);\
229 \ yy_ps = yyps = yys + ts;\
230 \ yy_pv = yypv = yyv + tv;\
231 \ maxyyps = &yys[yymaxdepth];\
233 \ if (yyv == NULL || yys == NULL)
235 if sed -f $tmp < $input > $output
236 then echo "The edit seems to have been applied okay."
237 else echo "The edit seems to have failed!"
241 ######################################################
244 echo "Unable to patch perly.c to allow dynamic yacc stack allocation (plan=$plan)"
245 # just do minimal change to write $output from $input
246 sed -e 's/Received token/ *** Received token/' $input >$output