On Fri, 29 Jul 2011 12:01:49 +1000, Gary Miller <g...@sumwise.com> wrote:
> Sam,
> 
> Exactly, thanks for the clarification and sorry about any confusion.
> 
> Anyone interested?
> 
> Gary

Hi Garry,

It interesting however I am too busy with other stuff.

Its easier to write a target for antlr 4, as writing a target for
antlr 3 is difficult, the string templates are complex.  This
is hard to reason on how to approach it as you need to keep in
your head the string template syntax and the syntax of the
programming language you are targetting (go).

While as with antlr4 the stringtemplate for the lexer is trivial
compared to antlr 3.  It seems that all that is required to get
started is to output:

- just the standard stuff to include/import/export stuff like in
any targe programming language file.

- the token ids in an enum or as constants or something like that.

- an array or list of token name strings.

- an array or list of rule name strings.

- a 16 bit unsigned ints into an array.  This is the key part, its
  the bytecodes that you need to interpret.

To start hacking the target stringtemplate, create the directory
for your target:

resources/org/antlr/v4/tool/templates/codegen/Go

copy the resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg
to
resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg

and just ignore most of the Java junk, and hack just the bits you need
to produce Go for only the lexer.  Start with the stuff on the lines
following:

Lexer(lexer, atn, actions, sempreds) ::= <<

When you encounter any issues with output strings, numbers, etc, then
in /h/argus/2/j/antlr4/g/antlr4/antlr4/tool/src/org/antlr/v4/codegen
you will need to create a file for your target:
/h/argus/2/j/antlr4/g/antlr4/antlr4/tool/src/org/antlr/v4/codegen/GoTarget.java

While hacking the stringtemplate just stick it in the front of your
classpath so antlr4 will find it, maybe in a antlr script something like:

#! /bin/sh
java -classpath 
/some_dir/antlr4/antlr4/tool/resources:/some_dir/antlr4/dist/antlr4.jar:/some_dir/j/antlr4/lib/ST-4.0.3.jar
 org.antlr.v4.Tool $*

Then you need to translate the Java code for the lexer runtime
interpreter into the target language, its in:

runtime/Java/src/org/antlr/v4/runtime/atn
 
The catch at the moment with targetting antlr 4 is Ter needs to
keep changing the source code all the time, so its somewhat challenging
to follow along.  Hopefully though the changes to the lexer are less
radical, and after you get the lexer done hopefully Ter will have
the parser more stable.

Thanks, Mark

> On Fri, Jul 29, 2011 at 11:55 AM, Sam Harwell
> <sharw...@pixelminegames.com>wrote:
> 
> > Hi Parsiad,
> >
> > I believe he's referring to creating a new ANTLR target/runtime for Go
> > (option language=Go), as opposed to using ANTLR to compile Go files into
> > executable code.
> >
> > Sam
> >
> > -----Original Message-----
> > From: antlr-interest-boun...@antlr.org
> > [mailto:antlr-interest-boun...@antlr.org] On Behalf Of Parsiad Azimzadeh
> > Sent: Thursday, July 28, 2011 7:51 PM
> > To: antlr-interest@antlr.org
> > Subject: Re: [antlr-interest] Interest in a Go lang port
> >
> > > Would anyone be interested in collaborating on a port of ANTLR to the Go
> > > lanaguage <http://golang.org/>?
> >
> > Interesting. What are your motivations for porting Go to ANTLR? I
> > believe the Go compiler is open source.
> >
> > --
> > Parsiad Azimzadeh
> > http://sfu.ca/~paa4
> >
> > 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 il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to