[antlr-interest] C# Just starting with Parsers, Trees
Doc In Nuke
docinnuke at gmail.com
Fri May 23 07:29:16 PDT 2008
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)
Best Regards,
Gavin Lambert wrote:
> At 03:12 23/05/2008, Doc In Nuke wrote:
> >One of the rule i added for exemple is the following one:
> >globalfuncdec : 'function' ^ funcname funcbody ;
> >
> >so for every global function (declaration not starting with local)
> >i get a subtree with the funcname and funcbody block.
> >Now what would really be nice is a way to get the funcname as 1
> >token and not more.
> >funcname is the following rule:
> > funcname : NAME ('.' NAME)* (':' NAME)? ;
>
> There's a few ways you can go here. One is to convert funcname into a
> lexer rule (but this may introduce problems into your grammar, if it's
> not sufficiently unique). Another is to keep it as separate tokens
> but put it into a subtree, like this:
>
> funcname : n=NAME (n+='.' n+=NAME)* (n+=':' n+=NAME)? -> ^(FUNCNAME $n+);
>
> I'm not completely sure about this last option (I've never used it
> myself), but I think you can also construct an imaginary token around
> it after the fact. Something like this:
>
> globalfuncdec : 'function' funcname funcbody -> ^('function'
> FUNCNAME[$funcname.text] funcbody);
>
> I think doing this causes it to lose the line/column information
> though; there is a way to preserve that but I'm not sure exactly how
> in this case.
>
>
More information about the antlr-interest
mailing list