Creating a Compiler in Java - Updated
Hey all,
well im thinking of creating a Compiler for my final year project and i just wanted to know if you have created a compiler before can tell me about your experiences and maybe recommened some reading material please.
All help is apperciated thanks for reading :)
Update - Apparently i need to have an academic question. im really stuck and i cant think of an academic question or a reason to create a compiler has anyone got any ideas? all help is apperciated could you please let me know thanks
Re: Creating a Compiler in Java
What do you want to compile?
Re: Creating a Compiler in Java
sorry i wanted it to compile Java aswell i should have wrote that in my 1st post lol.
Re: Creating a Compiler in Java
So you want to write a compiler in Java that compiles Java? Why not a game, IRC client, or something along those lines.
Re: Creating a Compiler in Java
Well i recently have done an IRC client and i havent done any game dev modules. it does sound a bit silly when i say i want to make a Compiler in java which is also written in java lol but i would like to know how the back end works etc and i think it should be an intresting topic.
Re: Creating a Compiler in Java
Well good luck. I have no clue where to start.
Re: Creating a Compiler in Java
You could start at the source (pun intended): The Compiler Group
Re: Creating a Compiler in Java
There's always the good old "Dragon Book".
It doesn't focus specifically on Java compilers, but it should be a great reference for creating compilers regardless of the language.
You will also probably want to familiarize yourself with Java ByteCode. This is what most Java compilers compile Java programs down to, then the JVM either interprets or performs a JIT to run the Java program (modern JVM's do the latter because it has significantly better performance).
Good luck, writing a compiler's pretty tough (especially if you want it to be any good).
Re: Creating a Compiler in Java
Hi all thanks for the replies i will look into the dragon book ive heard its lot of theory though :( lol well i think if i do choose to write a compiler it will only be a simple one and i have around 7 months to complete it.
Re: Creating a Compiler in Java
An idea: Create your own simple language to parse vs using a more complicated one.
Re: Creating a Compiler in Java
Thanks for that Norm quite a nice idea i have no idea where i would start at trying to make my own language lol
Re: Creating a Compiler in Java
Then take a subset of an existing one.
Re: Creating a Compiler in Java
Quote:
Originally Posted by
helloworld922
There's always the good old "
Dragon Book".
It doesn't focus specifically on Java compilers, but it should be a great reference for creating compilers regardless of the language.
You will also probably want to familiarize yourself with
Java ByteCode. This is what most Java compilers compile Java programs down to, then the JVM either interprets or performs a JIT to run the Java program (modern JVM's do the latter because it has significantly better performance).
Good luck, writing a compiler's pretty tough (especially if you want it to be any good).
Im doing a compiler class right now at uni, and the dragon book is core material. Pretty tough reading, but you really cant do a compiler without it (or a similar book).
I can safely say, that writing a compiler for the full Java 1.5 spec is not possible to do solo, unless you are already very experienced in compiler production, or you have a year++ to spend on it. As Norm said, do a subset of the java impl or simply your own simple language.
Take a look at compiler framework for java, sableCC. Once you get around the quirky syntax, it will save you a lot of time making a parser to abstract syntax trees.
Re: Creating a Compiler in Java
thanks for the comments everyone i will take your advise and use a java subset or just make my own simple language. i will let you know what i decide next wednesday after i have spoken to my supervisor. :)
Re: Creating a Compiler in Java
Update - Apparently i need to have an academic question. im really stuck and i cant think of an academic question or a reason to create a compiler has anyone got any ideas? all help is apperciated could you please let me know thanks
Re: Creating a Compiler in Java
There are a lot of "specialized languages" that take either build on to an existing language, or define a subset.
Examples would be OpenCL (variant of C99 with a strong vector/parallel processing core), Arduino C (variant of C, used to program the Arduino micro controller), MatLab (kind of like some scripting languages, designed for mathematical computation), etc.
edit:
I'm actually working on my own interpreter/compiler that can be used for math/scientific computations. It's based off Java, and I'm designing it so that components can be designed/used from Java, or using the interpreter I'm writing.
Re: Creating a Compiler in Java
How would I add an eternal scripting language to my game engine? Ive searched every where in google, and i cant find anything good.
Re: Creating a Compiler in Java
Hey yoda thanks yea i know ive looked and thought as much as i can however im just stuck lol.
Re: Creating a Compiler in Java
At the risk of stating the obvious, not so obvious, or obscure...a compiler is a tool - solving a question is more suited for an algorithm. Both are intertwined but quite different. Perhaps come at it from a different angle - think about a question to address, and not how to address a question..if that makes any sense :confused:
Re: Creating a Compiler in Java
Hi, I'm attempting to do a similar project and I have few tips if you're still interested:
As others have said, it is essentially pointless to create a compiler for Java (or a subset of Java). You need to do something new or different. That might be: extending an existing language to add new/missing features, or creating a completely new language (possibly to solve a certain problem).
Also It is probably best to make your compiler generate byte code for the JVM. The alternative options are to generate real machine code, or to create an interpreter to execute your language. I'd advise against the last two options as they would likely be too much work for a student project.
Lastly, you shouldn't need to write the lexical analyser or parser yourself. There are many different Java 'compiler-compilers' out there, The main ones are: SableCC (already mentioned), JavaCC, ANTLR, CUP, and Beaver. Which one you use will depend on the grammar of the language you are parsing, and maybe the design of your compiler.
I'd definitely recommend the book: "Modern Compiler Implementation in Java" by Andrew Appel, which tells you exactly how to go out writing a compiler in Java.
Re: Creating a Compiler in Java
Could u upload your project (compiler) please
my project is develop compiler in last project
to connect to me
https://www.facebook.com/engolfat.ameen