[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Bison generating C++
From: |
Hans Aberg |
Subject: |
Bison generating C++ |
Date: |
Wed, 18 Oct 2000 22:25:48 +0200 |
I have a suggest for Bison generating C++, namely to add an option that
cause it to write a file with a C++ ending, default say ".cc" instead of
".c". For now, it would do nothing else, but later one could first change
to C++ standard headers using namespaces, and even further down the road,
more C++ support.
I tweaked the Bison sources, to get this, as follows:
File getargs.c: Add
int generate_cplusplus = 0;
and in getargs(), add a "+" here ------>|
while ((c = getopt_long (argc, argv, "+yvdhrltknVo:b:p:", longopts, (int
*)0))
and to the switch statement, add the case '+', as follows:
switch (c)
{
case 0:
/* Certain long options cause getopt_long to return 0. */
break;
case '+':
generate_cplusplus = 1;
break;
...
Then in file files.c, add
extern int generate_cplusplus;
and in open_files() change to:
/* These are opened by `done' or `open_extra_files', if at all */
if (spec_outfile)
tabfile = spec_outfile;
else if (!generate_cplusplus)
tabfile = stringappend (name_base, base_length, ".c");
else
tabfile = stringappend (name_base, base_length, ".cc");
with a statement appending ".cc" if generate_cplusplus is set.
This does not check all combinations C++/calling for special file names. It
is just a tweak I happened to need.
One can think of a long option --C++, and that these options optionally can
have preferred filename extensions, one might be something like that -+.cpp
would make the files have extensions ".cpp" instead.
Hans Aberg
- Bison generating C++,
Hans Aberg <=
- Message not available