[antlr-interest] C# Just starting with Parsers, Trees
Doc In Nuke
docinnuke at gmail.com
Fri May 23 09:39:06 PDT 2008
Hi,
Darn, I am so stupid sometimes :)
I got around to figuring the thing with the funcname thingy but I was
looking at a way to concatenate the stuff and was thinking of doing it
afterwards :)
With your method it is one shot and I do not even have to recreate the
string after from the bits :)
Thanks a lot to all of you :)
Jim Idle wrote:
> On Fri, 2008-05-23 at 17:29 +0300, Doc In Nuke wrote:
>> Hi,
>>
>> Thanks for the information, however i am truly a beginner, what do I
>> need to get this to work in ANTLR:
>>
>> funcname : n=NAME (n+='.' n+=NAME)* (n+=':' n+=NAME)? -> ^(FUNCNAME $n+);
>>
>> I added a token at the start of the grammar named FUNCNAME but i still
>> have grammar errors :(
>> Do I need to declare n in a special way ?
>>
>> (if you have a link to a documentation on the site I ll gladly take it)
>>
>
> Your variables can only accumulate the same type, so you can't
> accumulate ':' and '.' and NAME. However, it is usually more useful to
> create nodes from the elements like ':' and '.' as this gives you a
> tree that helps resolve them (with symbol tables and so on. Of course
> if you are just going to 'print' them separately then you might not
> need that, in which case you probably don't need the n+= anyway.
>
> If you want a flat token sequence in the tree, but within a FUNC node
> then do this:
>
>
> funcname : ns=nameSequence -> ^(FUNCNAME $ns) ;
>
> nameSequence : NAME ('.' NAME)* (':' NAME)? ;
>
> If you want a tree (I usually do this, but as i say it is more useful
> when you are resolving name space sequences and so on, then use:
>
> nameSequence : NAME ('.'^ NAME)* (':'^ NAME)? ;
>
> And construct the tree grammar rules appropriately
>
> funcname: ^(FUNCNAME names) ;
>
> names : ^(':' nameSeq NAME)
> | nameSeq
> ;
>
> nameSeq : ^('.' nameSeq nameSeq)
> | NAME
> ;
>
> (Check that, I just typed it straight in to the email ;-).
>
> Jim
>
More information about the antlr-interest
mailing list