[antlr-interest] Newbie Needs help... StringTemplate and Language Translation

Kevina Choolhun kevina.choolhun at gmail.com
Thu May 22 04:43:09 PDT 2008


Hello again  everybody...

I  have been checking the Mantra Language and I am spell bound.

I am a student and would like a simple example of how to use StringTemplate
to translate a language. So far, I have 2 grammars, but i have been told I
need three. I am working on it. But still cannot get a hang of how to deal
with the StringTemplate bit.

Anybody can help me?

Thank you

Kevina


On Wed, May 21, 2008 at 6:44 PM, Kevina Choolhun <kevina.choolhun at gmail.com>
wrote:

> Thanks again... Me too havent got that deep yet... But I'm going to look
> into this...
>
> Thank you.
>
> Kevina
>
>
> On Wed, May 21, 2008 at 6:33 PM, Nikolas Everett <nik9000 at gmail.com>
> wrote:
>
>> I haven't gotten that deep into this as of yet, but the idea is to have
>> something like
>> class VerificationCallback {
>>  private final List<Error> errors;
>>
>>  public void import(ASTNode importedPackage) {//Do some checks, and add
>> errors to the list of errors}
>>   public void referencedType(ASTNode nodeForType) {//Do some checks, and
>> add errors to the list of errors}
>>
>> }
>>
>> You'd create the grammar with a member for the callback, and then you'd
>> call it when processing the tree like so:
>> import:  ^(IMPORT name=packageName) {this.callback.import(name);}
>>
>> --Nik
>>
>>
>> On Wed, May 21, 2008 at 10:13 AM, Kevina Choolhun <
>> kevina.choolhun at gmail.com> wrote:
>>
>>> Hello,
>>>
>>> Thanks! Could you please explain further what you mean by
>>>
>>> "1 grammar to verify the AST (tree grammar with no output, only embedded
>>> actions calling a callback)"
>>>
>>> Maybe, you mean error messages?
>>>
>>> Thank you.
>>>
>>> Kevina
>>>
>>>
>>> On Wed, May 21, 2008 at 5:59 PM, Nikolas Everett <nik9000 at gmail.com>
>>> wrote:
>>>
>>>> I learned a good portion of what I know about antlr and stringtemplate
>>>> by going through the source code for the Mantra compiler.  Its all here:
>>>> http://www.linguamantra.org/
>>>>
>>>> The long and short of it is that embedding actions is great for checking
>>>> things but is more cumbersome when actually generating output.  Tree
>>>> grammars that output templates are the way to go there.
>>>>
>>>> I tend to do:
>>>> 1 grammar to lex and parse into an AST (output=AST)
>>>> 1 grammar to verify the AST (tree grammar with no output, only embedded
>>>> actions calling a callback)
>>>> 1 grammar to generate output (tree grammar with output=template)
>>>>
>>>> This is wonderfully flexible because the grammars become modules,
>>>> allowing you to test them individually and substitute them at will.  This is
>>>> kind of a pain because you need to wrote three or more grammars and sync up
>>>> the output of the tree constructing grammar to the input of the others.
>>>>
>>>>
>>>> On Wed, May 21, 2008 at 9:45 AM, csanders <csanders at hoovers.com> wrote:
>>>>
>>>>> I'm also new to ANTLR and would like to know how StringTemplate is a
>>>>> better solution, is there somewhere we can read about this ?
>>>>>
>>>>> Thanks,
>>>>> Charlie
>>>>>
>>>>> Kevina Choolhun wrote:
>>>>>
>>>>>> Hello,
>>>>>>
>>>>>> I am new at ANTLR but with the help of The Definitive ANTLR Reference
>>>>>> have managed to set up a parser and a parser walker..
>>>>>>
>>>>>> Now for the next stage, I have tried my hand at embedding actions..
>>>>>> but Stringtemplate I hear is a much better solution.
>>>>>>
>>>>>> I am currently reading through stringtemplate.org <
>>>>>> http://stringtemplate.org>. I wanted to know if there are any nice
>>>>>> tutorials about it which could help me.. enhance my parser n lexer with
>>>>>> StringTemplate
>>>>>>
>>>>>> Thank you for your help.
>>>>>>
>>>>>> --
>>>>>> Kev
>>>>>>
>>>>>
>>>>>
>>>>
>>>
>>>
>>> --
>>> Kevina
>>
>>
>>
>
>
> --
> Kevina
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080522/e16f309a/attachment.html 


More information about the antlr-interest mailing list