home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1999 mARCH
/
PCWK3A99.iso
/
Linux
/
DDD331
/
DDD-3_1_.000
/
DDD-3_1_
/
ddd-3.1.1
/
ddd
/
yacctoC.sun
< prev
Wrap
Text File
|
1998-03-25
|
3KB
|
75 lines
# $Id: yacctoC.sun,v 1.5 1998/03/25 12:46:58 zeller Exp $
# Adapt YACC output for C++ usage
# (Happens to be working on my Sun using SunOS 4.1.1)
# Copyright (C) 1995 Technische Universitaet Braunschweig, Germany.
# Written by Andreas Zeller <zeller@ips.cs.tu-bs.de>.
#
# This file is part of the ICE Library.
#
# The ICE Library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# The ICE Library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with the ICE Library -- see the file COPYING.LIB.
# If not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# ICE is the incremental configuration environment.
# For details, see the ICE World-Wide-Web page,
# `http://www.cs.tu-bs.de/softech/ice/',
# or send a mail to the ICE developers <ice@ips.cs.tu-bs.de>.
# Declare functions
1i\
// This file was modified for -*- C++ -*-\
// using $RCSfile: yacctoC.sun,v $ $Revision: 1.5 $\
extern void yyerror(char *s);\
extern int yylex();\
# Undeclare malloc and realloc (not needed in C++ version)
s!extern char \*malloc(), \*realloc();!// &!
# Adapt yytoks[] to disable warnings
\!^yytoktype!,\!^}!s![^,]*,[^,]*!{&}!
# Make YYSTYPE a struct such that we can store class objects
# (use anonymous unions to save space!)
s!^typedef union\(.*\)$!typedef struct _YYSTYPE \1!
# Make sure we use new/delete instead of malloc/free
# (a MUST if we use class objects)
# (y*)malloc(x*sizeof(y)) -> new x[y]
s!([^\*]*\* *) *malloc *(\([^\*]*\)\* *sizeof *(\([^)]*\)) *)!new \2[\1]!g
# free(x) -> delete[] x
s!free *(\([^)]*\))!delete[] \1!g
# realloc -> own code
\!.*yymaxdepth += YYMAXDEPTH!,\!}!c\
int new_yymaxdepth = yymaxdepth + YYMAXDEPTH;\
YYSTYPE *new_yyv = new YYSTYPE [new_yymaxdepth];\
int *new_yys = new int [new_yymaxdepth];\
if (new_yyv == 0 || new_yys == 0)\
{\
yyerror( "yacc stack overflow" );\
return(1);\
}\
for (unsigned yycopy = 0; yycopy < yymaxdepth; \
yycopy++)\
{\
new_yyv[yycopy] = yyv[yycopy];\
new_yys[yycopy] = yys[yycopy];\
}\
yymaxdepth = new_yymaxdepth;\
delete[] yyv; yyv = new_yyv;\
delete[] yys; yys = new_yys;