[antlr-interest] newbi question : operator + any

Marco Laponder marco.laponder at kewill.com
Tue Feb 7 22:58:20 PST 2012


Lets explain what I am trying to accomplish, maybe you can provide me
the most impressive grammars :-)

 

I am trying to parse a filter string which filter on a column of a
table, so I need to know the operator. In my example I stated the '>'
but of course I would like to expand it to '<','>=' etc and alter on
even add parenthesis, 'and' and 'or' etc. But I would like to start
simple as I am new at ANTLR.

 

Your sample does the trick, however looks hard to maintain, e.g., when I
add the '<' to COMPARE I also need to add it to ANYTHING. (Well it seems
still more maintainable than a single regular expression no one
understands to do the trick ;-) )

 

Kind regards,
Marco

 

________________________________

Van: Marco Laponder 
Verzonden: dinsdag 7 februari 2012 8:45
Aan: 'Gokulakannan Somasundaram'
CC: antlr-interest at antlr.org
Onderwerp: RE: [antlr-interest] newbi question : operator + any

 

This still gives me the same error, any other ideas ? Of is antlr just
not appropriate for this ?

 

Kind regards,

Marco

 

________________________________

Van: Gokulakannan Somasundaram [mailto:gokul007 at gmail.com] 
Verzonden: maandag 6 februari 2012 16:56
Aan: Marco Laponder
CC: antlr-interest at antlr.org
Onderwerp: Re: [antlr-interest] newbi question : operator + any

 

COMPARE : '>';

ANYTHING : (~'>')(.)*;

testExpression : COMPARE ANYTHING; 

 

 

Try this.

 

Gokul.

On Mon, Feb 6, 2012 at 8:30 PM, Marco Laponder
<marco.laponder at kewill.com> wrote:

Hi All,



I am trying to setup a very simple grammar, ik should be able to handle



"> thiscouldbeanything"



So I tried:



COMPARE : '>';

ANYTHING : (.)+;

testExpression : COMPARE ANYTHING;



but when generating java resources it gave me the error:



"The following alternatives can never be matched: 1"



The problems seems to be the ANYTHING, so how should I define a grammar
to be able to handle this ?



Kind regards,

Marco


List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

 



More information about the antlr-interest mailing list