[antlr-interest] Porting a runtime to Ada
Luke A. Guest
laguest at archangeli.co.uk
Tue May 22 04:17:17 PDT 2007
On Tue, 2007-05-22 at 13:08 +0200, Benjamin Niemann wrote:
> Hi,
>
> Luke A. Guest wrote:
>
> > I take it all the files in the
> > antlr-3.0/runtime/Java/src/org/antlr/runtime/ directory are needed to be
> > ported for a full back-end?
>
> Plus antlr-3.0/src/org/antlr/codegen/templates/Java/*.stg and perhaps create
> an antlr-3.0/src/org/antlr/codegen/Ada95Target.java
Yup, already started looking at this.
> But it is in fact pretty easy to get started:
>
> * In src/org/antlr/codegen/templates/
> - create a directory Ada95
> - copy Java/Java.stg to Ada95/Ada95.stg
I take it the capitalisation is necessary, i.e. if I use options
{ language = ada95; } does the directory and template group need to be
named ada95?
> * I recommend building the ANTLR tool 'in place'. Do not create a jar or
> compile/copy to a build directory. When you run it with 'java -cp
> path-to-src-dir ...' it will use the original *.stg file, which you'll edit
> a lot - so rebuilding the tool would be quite a PITA.
Hmm, was going to just build using ant, as I know how to do that fine ;)
and it's quick enough, that way I can just use the generated jar in the
lib dir.
> * Create a directory antlr-3.0/runtime/Ada95. Here you can put anything you
> need (no need to clone Java 1:1).
>
> * Start with a simple lexer like:
>
> lexer grammar T;
> options { language = Ada95; }
> ZERO: '0';
>
> * Look at the generated code and try to figure out which templates in
> Ada95.stg you have to port to get valid Ada95 code. What I did, is to
> comment out the Java code in all templates replacing it with something like
> FIXME([number]). Then you fix the templates until no FIXME remains in the
> output.
Ah, so this is how you start out! I did wonder what the best way forward
was.
> * You'll need a basic implementation of a character stream and base
> recognizer/lexer to get the example running. Just implement the methods
> that are actually needed to get the example running w/o errors.
Yeah, I noticed that the Java implementation returns ints (32 bit), do
all the ports do this? It reads in UTF-8 and transforms it to 32 bit
characters? In Ada you have Character and Wide_Character.
> * You'll either get the feeling "Wow, that was easy!" and move on (that
> happened to me) or "Eeek, what a pain!" and let someone else to the work.
Well, I think it'll be fine up to the parser ;) But that at least should
be ok-ish.
Thanks,
Luke.
More information about the antlr-interest
mailing list