If you want Java as a target, just use the ASM .class generator. It is nice and easy and you can write any support/runtime classes quickly and easily in Java. Create a code generator class and call methods within it as you walk your tree. You could also get LLVM to do this for you in a similar fashion.
If you are targeting a text output, then just use StringTemplate and percolate the templates up your tree to the top rule. You can also generate LLVM intermediate code this way too. Look for examples in the Language Implementation Patterns book. ASM and the JVM would be relatively easy :-) Jim > -----Original Message----- > From: [email protected] [mailto:antlr-interest- > [email protected]] On Behalf Of William v Doorn > Sent: Friday, April 09, 2010 12:20 PM > To: Andreas Stefik > Cc: [email protected] > Subject: Re: [antlr-interest] Building own interpreter > > How am I going about this? I generated those basic Java files, but what > now? > > I'm trying to make a simple DSL to make it easier for my developers to > create specific code. > > 2010/4/9 Andreas Stefik <[email protected]> > > > If it doesn't matter for your particular application at all, then > > cliff's suggestion is probably best. Just emit out code that can be > > read by a traditional compiler (e.g., gcc). Only design a full > > evaluator/interpreter if your application (whatever it is), demands > > it. > > > > Stefik > > > > On Fri, Apr 9, 2010 at 2:13 PM, Cliff Hudson > <[email protected]> > > wrote: > > > If you decide to go the compiled route, also consider just writing > a > > > translator from your language to a compiled one, such as C or C++. > Then > > you > > > don't have to implement a compiler at all which will save you a ton > of > > time. > > > > > > > > > On Fri, Apr 9, 2010 at 12:09 PM, Andreas Stefik <[email protected]> > > wrote: > > >> > > >> That's hard to answer without knowing context. Compilers are > tricky > > >> things. For example, you might make a simple evaluator that will > > >> inevitably run very slowly, but do the job you need. Or, you might > > >> make something that generates code that ultimately be compiled > into > > >> very fast C code to be compiled by a GCC compiler --- or who knows > > >> what. > > >> > > >> That's why I'm saying it depends on context. What problem are you > > >> trying to solve with your DSL? > > >> > > >> Stefik > > >> > > >> On Fri, Apr 9, 2010 at 1:59 PM, William v Doorn < > > [email protected]> > > >> wrote: > > >> > Andreas, > > >> > > > >> > Well, I can already execute some code and evaluate it, but is > this > > >> > really > > >> > the way to do it? e.g. could I use this as interpreter, or do I > need a > > >> > fully > > >> > different approach? (see the file I attached) > > >> > > > >> > Thanks > > >> > > > >> > William van Doorn > > >> > > > >> > > > >> > > > >> > 2010/4/9 Andreas Stefik <[email protected]> > > >> >> > > >> >> William, > > >> >> > > >> >> This is a complex question to answer, and it really depends on > your > > >> >> needs. For example, creating a whole compiler from scratch is > > >> >> difficult, but possible. We have our own compiler (with an > ANTLR > > front > > >> >> end), that integrates our own custom language, called HOP, > which is > > >> >> basically a novice programming language we distribute to > schools for > > >> >> the blind. Our implementation is on sourceforge and is under > GPL2, so > > >> >> you are welcome to look at it (Search for "Sodbeans"). We also > > >> >> integrate our custom compiler into NetBeans. > > >> >> > > >> >> On the other hand, if your needs allow it, you can also do > things > > like > > >> >> have your antlr grammar generate java byte code or assembly > directly, > > >> >> which is sometimes easier, again depending on what you need. > And very > > >> >> simple interpreters for very simple languages aren't too tough, > if > > you > > >> >> know what you are doing, and depending on your requirements. > > >> >> > > >> >> Hope that gives you some tips, at least. Short answer: Yes, > it's > > >> >> definitely possible, but it depends on your goals, and it's > typically > > >> >> not something you would bang out in a weekend. > > >> >> > > >> >> Andreas Stefik, Ph.D. > > >> >> Department of Computer Science > > >> >> Southern Illinois University Edwardsville > > >> >> > > >> >> On Fri, Apr 9, 2010 at 1:44 PM, William v Doorn > > >> >> <[email protected]> > > >> >> wrote: > > >> >> > Hello all, > > >> >> > > > >> >> > I've been reading the The definitive ANTLR book and I've made > my > > own > > >> >> > small > > >> >> > language using the AST strcuture. > > >> >> > > > >> >> > Now I was wondering, is it hard to make my own > compiler/interpeter > > >> >> > for > > >> >> > this? > > >> >> > I can feed files and such to it, but how would I make my own > > >> >> > interpreter/compiler? > > >> >> > > > >> >> > Thanks, > > >> >> > > > >> >> > William van Doorn > > >> >> > > > >> >> > List: http://www.antlr.org/mailman/listinfo/antlr-interest > > >> >> > Unsubscribe: > > >> >> > > > >> >> > > > http://www.antlr.org/mailman/options/antlr-interest/your-email- > address > > >> >> > > > >> > > > >> > > > >> > > >> List: http://www.antlr.org/mailman/listinfo/antlr-interest > > >> Unsubscribe: > > >> http://www.antlr.org/mailman/options/antlr-interest/your-email- > address > > > > > > > > > > List: http://www.antlr.org/mailman/listinfo/antlr-interest > Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your- > email-address List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address -- You received this message because you are subscribed to the Google Groups "il-antlr-interest" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en.
