compiler with bison / flex

P

Philipp Kraus

Hello,

I must create my own programming language. So I download bison and flex
and install them. I had tested bison with C examples and I can create my files,
but I need C++ code. I'm new at this topic, so I need some examples / help
for create C++ code.

I my testcode I write:
%{
#includes <iostream>
void yyerror (const char *error);
int yylex( void );
%}

%%
expr : ;
%%

int main( void )
{
return yyparse();
}

void yyerror( const char *error )
{
std::cout << error << std::endl;
}

int yylex( void )
{
return -1;
}

If I compile this with bison, I would get an *.c file. How I can
get a *.cpp file?

I hope this thread isn't off-topic.

Thx

Phil
 
J

James Kanze

Philipp said:
I must create my own programming language. So I download
bison and flex and install them. I had tested bison with C
examples and I can create my files, but I need C++ code.
[..]
I hope this thread isn't off-topic.
It is, sorry. Those tools aren't part of the C++ language.
You should consider asking in the newsgroup for the OS you're
using, or in 'comp.compilers'. Have you tried looking on the
web? What if you just rename your resulting C files (or run
then through a C++ compiler without even renaming)? I know,
there aren't probably the answers you're looking for. It
would be nice to have a command-line switch that would just
generate C++ code for you, but I am not certain there is such
a switch, and discussing tools except the ones directly
related to C++ language, like a compiler, is usually off-topic
here.

FWIW: either bison or flex (or perhaps both, I forget) do have
an option to generate C++. At least the last time I tried it,
it was somewhat antiquitated C++ (#include <iostream.h>, ostream
without a namespace, etc.). But generally, a little bit of
post-processing with sed does the trick (even if you generated
C, and not C++). The only problem is that the post-processing
tends to depend on the version of the tool you're using.
 
P

Philipp Kraus

Philipp said:
I must create my own programming language. So I download
bison and flex and install them. I had tested bison with C
examples and I can create my files, but I need C++ code.
[..]
I hope this thread isn't off-topic.
It is, sorry. Those tools aren't part of the C++ language.
You should consider asking in the newsgroup for the OS you're
using, or in 'comp.compilers'. Have you tried looking on the
web? What if you just rename your resulting C files (or run
then through a C++ compiler without even renaming)? I know,
there aren't probably the answers you're looking for. It
would be nice to have a command-line switch that would just
generate C++ code for you, but I am not certain there is such
a switch, and discussing tools except the ones directly
related to C++ language, like a compiler, is usually off-topic
here.

FWIW: either bison or flex (or perhaps both, I forget) do have
an option to generate C++. At least the last time I tried it,
it was somewhat antiquitated C++ (#include <iostream.h>, ostream
without a namespace, etc.). But generally, a little bit of
post-processing with sed does the trick (even if you generated
C, and not C++). The only problem is that the post-processing
tends to depend on the version of the tool you're using.

Thanks for the hint ;-P
Do you know another tool to create my own language?
I would like to write the grammer in Backus-Nauer structure
and generate C++ Code

Phil
 
M

Michael Oswald

Thanks for the hint ;-P
Do you know another tool to create my own language?
I would like to write the grammer in Backus-Nauer structure
and generate C++ Code

ANTLR/PCCTS? At least the last time I used it (about 7 years ago), I
created some C++ with it.

lg,
Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,218
Latest member
JolieDenha

Latest Threads

Top