Re: Is Java useful for writing (C/C++) compiler

iank@bearcave.com (Ian Kaplan)
20 Apr 2000 00:37:25 -0400

          From comp.compilers

Related articles
Is Java useful for writing (C/C++) compiler vdbent@mail.com (Kees & Annette van der Bent) (2000-04-16)
Re: Is Java useful for writing (C/C++) compiler patrykz@ilion.eu.org (Patryk Zadarnowski) (2000-04-16)
Re: Is Java useful for writing (C/C++) compiler rsherry@home.com (Robert Sherry) (2000-04-17)
Re: Is Java useful for writing (C/C++) compiler pmb@dina.kvl.dk (Peter Bertelsen) (2000-04-17)
Re: Is Java useful for writing (C/C++) compiler gram@ull.mjolner.dk (Flemming Gram Christensen) (2000-04-20)
Re: Is Java useful for writing (C/C++) compiler iank@bearcave.com (2000-04-20)
Re: Is Java useful for writing (C/C++) compiler jandk@easynet.co.uk (Jonathan Barker) (2000-04-20)
Re: Is Java useful for writing (C/C++) compiler dale@cs.rmit.edu.au (dale) (2000-04-21)
Re: Is Java useful for writing (C/C++) compiler dvdeug@x8b4e53cd.dhcp.okstate.edu (2000-04-21)
Re: Is Java useful for writing (C/C++) compiler nr@labrador.eecs.harvard.edu (2000-04-25)
Re: Is Java useful for writing (C/C++) compiler jandk@easynet.co.uk (Jonathan Barker) (2000-04-25)
Re: Is Java useful for writing (C/C++) compiler bobduff@world.std.com (Robert A Duff) (2000-04-25)
[2 later articles]
| List of all articles for this month |

From: iank@bearcave.com (Ian Kaplan)
Newsgroups: comp.compilers
Date: 20 Apr 2000 00:37:25 -0400
Organization: Deja.com - Before you buy.
References: 00-04-125
Keywords: Java, practice

    vdbent@mail.com wrote:
> [ pros and cons of writing a C or C++ compiler in Java? ]


    I like Java, in some ways better than C++. I am also a believer in
compiling Java into native code "ahead of time" (see
http://www.bearcave.com/software/java/why_native.html). However
native compilers are just starting to become available. I have chosen
to implement my Java compiler in C++ after much thought. My reasons
are:


    1. Interpreted Java is slow. There has been a lot of propaganda
from Sun stating that Java performance is not a problem. But
companies like towerJ would not be in business if this were true. I
have written a class file disassembler in Java which is far slower
than I would have expected. Again, see the web page referenced above.


    2. I want direct access to the operating system. I want to be able
to control memory allocation for large compiler data structures and to
directly call POSIX functions. This is difficult with Java.


    The argument against C++ is portability. For example, I am
concerned about using advanced features of the Standard Template
Library (STL), like allocators for fear that they may not be portable.
Also, if I have a bug because of portability issues, the STL is not
that transparent (e.g., it may take a while to figure out what went
wrong). C++ has many more portability problems than C ever did. So I
try to use only as many features of C++ as I need for good
abstraction. And I compile my code on both Windows and UNIX to test
portability (this is better than nothing, but obviously not
definitive).


    People in this group and elsewhere are probably tired of hearing
about how much I like ANTLR. To them, my apologies. Here it is
again. I'm very happy with ANTLR. There is a very nice C grammar for
ANTLR (see www.antlr.org). ANTLR will generate both C++ and Java
parsers. So my choice would be to use ANTLR (the second generation
PCCTS) and generate a C++ parser. I would do my own AST generation
using C++ actions in the ANTLR parser rules, rather than using ANTLR's
default trees.















Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.