[antlr-interest] Fwd: passing arguments to the templates

swathy murthy pskswathy at gmail.com
Sat Mar 13 08:46:06 PST 2010


I have started using HashMap to track the variables. But, my problem
still remains the same. In my t.g grammar, if you look at the parser
rule

stat : ^(SAL_PROGRAM ^(DECLARATION specification_root)) ->
outer_template(var = {locals.get($LITERAL.text)});

I need to use a variable which is not mentioned in the rule. So, how
can I go about doing that. Its giving the error of not recognizing the
variable LITERAL. So, how can I make a reference. I have attached all
my modified grammars.

And, regarding the rules not emitting the tree nodes, could you please
point them out. If you are talking about expr, exp and term, they are
not disturbed to match the input and in tree grammar g, I have clubbed
them all. I know my grammar is a lot confusing. Its because of the
language I am working on and due to my lack of programming skills.
And, I have not pasted whole of my grammar. I have pasted only the
part I'm working on right now.
I did not understand following points mentioned:
a) why are you having two set of parser rules, one inside m.g and another
inside g.g
b) using literals inside parser grammar is not recommended
Would you be kind enough to explain me clearly.

Thanks a lot.
Swathy

On Mon, Mar 8, 2010 at 9:48 AM, Gokulakannan Somasundaram
<gokul007 at gmail.com> wrote:
> I haven't used much of tree grammar, but your stuff looks very confusing.
> a) why are you having two set of parser rules, one inside m.g and another
> inside g.g
> b) using literals inside parser grammar is not recommended
> c) i see only a hashmap declaration and i am not seeing the usage of it
> d) There are certain rules which are not emitting tree nodes, but they seem
> to be the important ones.
>
>
> Gokul.
>
> On Fri, Mar 5, 2010 at 10:38 PM, swathy murthy <pskswathy at gmail.com> wrote:
>>
>> Hi
>>
>> Actually, I tried using Hash Map long back. But, it did not work out.
>> And, the main thing is that I just need to store the name of the
>> variables. I do not need the values as I am not executing any actions
>> in the grammar. I am just using it as a language converter. Could
>> anyone please suggest me how to do that looking at my grammar files
>> which are attached.
>> m.g is the main grammar file from which I am creating a tree grammar
>> g.g and from the tree grammar, I am creating a template t.g.
>> And, also I need to generate some temporary variables automatically
>> based on number of input variables. Would it be possible to generate
>> variables automatically and store each variable as a template or using
>> hash map.
>>
>> Thanks.
>> Swathy
>>
>> On Fri, Mar 5, 2010 at 11:44 AM, Gokulakannan Somasundaram
>> <gokul007 at gmail.com> wrote:
>> > Keep track of things using a hashmap.
>> > insert into the hashmap at expr and retrieve them at stat and pass it to
>> > the
>> > template.
>> >
>> > Gokul.
>> >
>> >
>> > On Fri, Mar 5, 2010 at 12:06 AM, swathy murthy <pskswathy at gmail.com>
>> > wrote:
>> >>
>> >> Hi
>> >>
>> >> I have attached my grammar file and the template file. Now, I need to
>> >> pass the value of the LITERAL in the rule expr to outer_template() in
>> >> rule stat.
>> >> I am directly using outer_template(var={$LITERAL.text}) but this is
>> >> not working. It gives the error that it cannot find the symbol
>> >> LITERAL.text as it is not present in the rule stat. So, how should I
>> >> pass the argument to the template.
>> >> Help would be appreciated.
>> >>
>> >> Thanks a lot.
>> >> Swathy
>> >>
>> >>
>> >> 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
>>
>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: g.g
Type: application/octet-stream
Size: 1207 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20100313/dd9992f1/attachment.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: m.g
Type: application/octet-stream
Size: 1544 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20100313/dd9992f1/attachment-0001.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Main.java
Type: application/octet-stream
Size: 2437 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20100313/dd9992f1/attachment-0002.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: t.g
Type: application/octet-stream
Size: 809 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20100313/dd9992f1/attachment-0003.obj 


More information about the antlr-interest mailing list