[antlr-interest] newbi question : operator + any

Marco Laponder marco.laponder at kewill.com
Thu Feb 9 22:08:13 PST 2012


Hi,

 

Let tackle your questions:

 

Q1: I was struggling with this question myself, as I was explaining
earlier for now it is pretty simple, a comparison operator followed by a
string which is nog problem to handle with a regular expression. However
I would like to enhance this later on, with parenthesis, 'and', 'or'
constructions etc. So in the future I might be able to handle a string
like : 
( > a && < b) || ( (<=c and >=f )  or (== f) )
which is harder (for me anyway) to handle with a regular expression

 

Q2: ANYTHING is really anything, the grammar is for a filter language on
a table for a specific column, and as the user (especially my users I
think ;-) ) must best be able to filter on anything in the table I have
no additional restrictions there. The data in the table can contain
anything, and therefore the filter can contain anything

 

I am working with antlr v3 right now, but if v4 is the better way to go
there is no problem there as I am just getting started. Regarding the
books, there you have a fair point. I will look what the ANLTR bibles
are.

 

Kind regards,

Marco

 

________________________________

Van: Kyle Ferrio [mailto:kferrio at gmail.com] 
Verzonden: woensdag 8 februari 2012 15:52
Aan: Marco Laponder
Onderwerp: Re: [antlr-interest] newbi question : operator + any

 

Hi,

I'm joining the thread late, but this sounds a bit like an experience I
have seen a few times. Sometimes trying to make things "too simple"
actually makes lexing and parsing more difficult.  While is is often
good to defer decisions in software as long as possible, it is also
helpful to use all of the information at our disposal.  That probably
seems vague, so here are some questions to consider. 

Q1: Is your application likely to grow in syntactic and/or semantic
complexity to a point that its needs cannot be economically met by a
simple filter implemented, say, with GNU awk?  I'm not trying to
discourage you from using ANTLR.  ANTLR is awesome.  But the difference
in costs between the two approaches is large, so it makes sense to ask.

Q2: Do you have any stronger guarantees on the form of the input?  For
example, is  ANYTHING really anything (excluding a finite set of
operators)?  Or are legal operands actually restricted, say, to the set
of common alphanumeric identifiers and possibly literal values?  If so,
your work just got vastly easier.

I don't recall whether you mentioned that you're working with antlr v3
or the yet-to-be-released v4.  I suggest pursuing the examples
appropriate to your version from the antlr website.  (Note that antlr v4
provides greatly enhanced expressiveness for expression-parsing, but
examples for v3 are much more plentiful at the moment.)

Also, definitely get your hands on the two ANTLR books.  They'll save
you time and are actually a lot of fun if you're into this sort of
thing.

Best Luck,
Kyle



On Tue, Feb 7, 2012 at 11:58 PM, Marco Laponder
<marco.laponder at kewill.com> wrote:

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




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