[antlr-interest] newbi question : operator + any

Marco Laponder marco.laponder at kewill.com
Mon Feb 13 01:28:24 PST 2012


Well, although @4dUbb%ez_5&q is not likely, it is a valid filter string,
as all the characters could be present in a field of the table to be
filtered. A '@' could e.g. be present in a mail address, the '&' in a
name (Bang & Olufsen), etc. So I would consider  @4dUbb%ez_5&q valid. I
understand parsing for an identifier would be more simple, but not
sufficient for my case.

 

Kind regards,
Marco

 

________________________________

Van: Kyle Ferrio [mailto:kferrio at gmail.com] 
Verzonden: vrijdag 10 februari 2012 21:10
Aan: Marco Laponder
Onderwerp: RE: [antlr-interest] newbi question : operator + any

 

Ok.  You do want to parse grouped  combinations of Boolean expressions.
So you almost certainly want a parser, not an awk filter.

But I note with interest that the instances of ANYTHING in your examples
are limited to lower case alpha.  Ask yourself this... Would
@4dUbb%ez_5&q be a valid ANYTHING in your language?  If not, why not?  A
non-null answer will define an identifier pattern which restricts the
class, so that the kind of awkward problem you're encountering now
simply won't arise.  This is easier to see after doing than before
doing.

BTW, you're actually grappling with the edges of a pretty profound
linguistic/semiotic question, namely what do we mean by 'language' and
how do we discriminate (much less parse) language from noise.  I'm not
smart enough to answer that, which is off-topic for this listserv
anyway.  So I just try to make things simple and get work done.  I think
specifying an IDENTIFIER class in place of your ANYTHING will make your
task much easier.

Kyle

On Feb 9, 2012 11:08 PM, "Marco Laponder" <marco.laponder at kewill.com>
wrote:

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