Gavin,
Again, thanks for the fast response.
2009/9/15 Gavin Lambert <[email protected]>
>
> >tokens{
> > BLOCK = '_block';
> >}
>
> That is *not* an imaginary token. Remove the '= ...' part or
> it'll actually try to match that in the input.
>
I didn't understand this at first because it seems to work the same both
ways. However, I just remembered that I used a variable name in my language
that got flagged by the compiler as being the same as one of the virtual
tokens like the one above. I could not understand it at the time and put an
'_' in front of all the virtual tokens so that there would be no clash. In
my language I have many like this because I saw it in an example somewhere.
I shall strip out all the values, I assume that it will also make the
parsing more efficient.
> If not, then you should express the optionality externally:
>
> start : sentences? EOF ;
> sentences : sentence (DOT sentence)* -> sentence+ ;
> sentence : WORD | block ;
> block : '[' sentences? ']' -> ^(BLOCK sentences?) ;
>
> (I've also changed the sentences rule to use iteration rather than
> recursion, which is more efficient.)
>
> Much better, thanks. I have done the appropriate changes to my language and
can now have an empty block (of course I am now wondering whether that
should be a valid construct but that's another matter!).
You have also indirectly helped me with my lexer include files.
I think ANTLR is an amazing tool. When I think back to my yacc days ...
Cheers,
Kevin
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address