[antlr-interest] Problem with Separators

Sohail Somani sohail at taggedtype.net
Sun Dec 25 23:06:20 PST 2005


On Mon, 2005-12-26 at 07:50 +0200, Craig Main wrote:

> I am using a grammar and a tree to recognise a simple expression
> grammar.
> 
> At the moment, the rules for using semi colons ‘;’ are very strict,
> and I need to relax them somewhat.

I think the problem is simplified if you don't ignore end of lines. That
is, if you can say that this is not a valid statement:

if (blah) {
c 
=
10;
}
else
{
c
=




15+


414123;
}

If this is an invalid statement (its valid c++, assuming appropriate
declarations), then you can have SEMI_COLON | EOL as your rule
terminator.

Now, if its a valid statement, I am not so sure what you can do. The
python guys mustve had to do a similar thing, but then the properly
translated snippet above wouldn't be a valid sentence. So, make your
life easier and make it an invalid statement. If you need to justify it,
you can always say that it forces people to break up complicated
expressions :) The c++ grammar is also available www.antlr.org but I'd
be scared to look at that guy.

BOL!

Sohail



More information about the antlr-interest mailing list