[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: bison-includes for additional definitions and rules
From: |
Wayne Green |
Subject: |
RE: bison-includes for additional definitions and rules |
Date: |
Thu, 1 Aug 2002 12:13:38 -0600 |
Perl script.
#!/usr/bin/perl -w
#############################################################################
#
# yaccpp.pl -- Yacc preprocesor. Make it so we can only have one set
# of token declarations.
# perl yaccpp.pl master.yy > master.y
# -w to permit warnings to be sent to make's output.
#############################################################################
#############################################################################
# includeum -- Include this file in stdout.
#############################################################################
sub includeum
{
local($file,$input) = @_; # get the file to include
open($input,$file) || die "Unable to open file $file.";
while(<$input>)
{
if(/^!!/)
{
$newfile = substr($_,2);
includeum($newfile,'fh02');
} else {
print $_;
}
}
close($input);
}#includeum
#############################################################################
# main
#############################################################################
foreach $argfile (@ARGV)
{
includeum($argfile,'fh01');
}
# end-of -script
add a line starting with !! to your base yacc file (I use extension .yy"
and produce .y files with script):
!!datetime.yytypes
-------- In context...
%{
#include ... /* std c include statament section... !! works here too */
%}
%union {...}
%type ...
/* include the predefined types for shared rules about date and time */
!!datetime.yytypes
%%
/* my rules */
/* include the predefined rules */
!!daterules.yy
%%
------ Makefile
Foo.c : foo.yy datetime.yytypes daterules.yy otherstuff
$(YACCPP) foo.yy > foo.y
$(YACC) $(YACCSWITCHES) foo.y
-- Should just about do it. I brewed up the perl script, and it only nests
once. (!! files in the top level file only) Anybody have one that nests
more, let me know.
I typically develop under windows, so this message has been twisted a tad
to reflect what you might do under Linux/Unix.
Under MKS make/perl for windows:
YACCPP = perl yaccpp.pl
--Wayne
Wayne Green InfoSavvy, LLC
address@hidden
> -----Original Message-----
> From: address@hidden [mailto:address@hidden
> Behalf Of Roul Oldenburger
> Sent: Thursday, August 01, 2002 1:12 AM
> To: address@hidden
> Subject: bison-includes for additional definitions and rules
>
>
> Hello there,
> I am new to the UNIX and Linux tools lex/yacc, flex/bison and I am
> looking for a way to include additional definitions and rules from `add-
> on` yacc files to a main-yacc-file. Because it seems to me that yacc
> does not implement any `yacc-includes´ I asked myself if Bison
> probably does implement such a possibility? If not, does somebody
> know an easy workaround?
>
> Thanks in advance
> Roul
> ______________________________________________________
> Multimedia Messaging ist da! Die Zukunft des Messaging hat begonnen.
> http://mobile.lycos.de/mobile/local/mms/
>
>