[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Building a simple "compiler"
Hi Roger.
SableCC is the tool you are looking for.
I did not understand why you would need to build a compiler. An
interpreter would probably do the work. Building a compiler is an order
of magnitude harder than building an interpreter as you have to
understand clearly:
1- the source language (you desing it)
2- the implementation language (Java)
3- the destination language (Assembly, bytecode, ...)
4- the rules to translate "1" into "3".
If you want to desing your own language, and build an interpreter for
it, here is my advice:
1- Start with the MiniBasic interpreter
(http://sourceforge.net/project/filelist.php?group_id=3239).
2- Add a few additional statements that perform the commands you want to
implement (in the grammar).
3- Add new methods that implement these commands in the interpreter
class.
This would allow you to get complete running interpreter in a few
minutes/hours of work.
Good luck!
Etienne
Roger Pomeroy wrote:
>
> Hi -
> I am looking for info in general on building a translator or compiler for a
> custom language.
>
> I currently use a program which has a rather cryptic set of commands to
> process data. I would like to define my own "grammar" that is easier to
> read/understand, and then have the "compiler" translate this to the commands
> that the program actually uses.
>
> I am looking for a tool to automate this process. I am moderately
> comfortable with programming, but am certainly no expert. Defining the
> syntax I want in BNF form is no problem, but the difficulty is in generating
> the actual program to translate it to the desired command language.
>
> Is sablecc able to do this? If not, can you point me in a direction of a
> tool that I can use?
>
> THanks
> rp
>
> ______________________________________________
> FREE Personalized Email at Mail.com
> Sign up at http://www.mail.com/?sr=signup
--
----------------------------------------------------------------------
Etienne M. Gagnon, M.Sc. e-mail: egagnon@j-meg.com
Author of SableCC: http://www.sable.mcgill.ca/sablecc/
----------------------------------------------------------------------