[GRASS5] PATCH: sql expression parser

Daniel Calvelo Aros dcalvelo at minag.gob.pe
Sun Jun 19 18:24:42 EDT 2005


Ok, Glynn's latest patch compiles and seems to work under both MacOSX and
linux. I mean:

Input statement: -->>select a from b where -(1+a)/-(b+c)<1 and not a>2 or not
not a=1<<--
********** SQL PARSER RESULT **********
INPUT: select a from b where -(1+a)/-(b+c)<1 and not a>2 or not not a=1
COMMAND: SELECT
TABLE: b
COLUMN  1: a
WHERE:
op: OR
  op: AND
    op: <
      op: /
        op: -
          val: 0
          op: +
            val: 1
            col: a
        op: -
          val: 0
          op: +
            col: b
            col: c
      val: 1
    op: NOT
      op: >
        col: a
        val: 2
  op: NOT
    op: NOT
      op: =
        col: a
        val: 1
ORDER BY: (null)
***************************************

Paul, could you commit?

Daniel.


-- Daniel Calvelo Aros

---------- Original Message -----------
From: Glynn Clements <glynn at gclements.plus.com>
To: "Daniel Calvelo" <daniel.calvelo at minag.gob.pe>
Cc: grass5 at grass.itc.it
Sent: Wed, 15 Jun 2005 13:04:30 +0100
Subject: Re: [GRASS5] PATCH: sql expression parser

> Daniel Calvelo Aros wrote:
> 
> > > The SQL interpreter in the DBF driver doesn't have a negation
> > > operator.
> > > 
> > > I thought about parsing -E as a subtraction (0 - E), although I'm not
> > > sure whether there's something I'm overlooking.
> > 
> > I'd rather use (-1)*E, which is also within the grammar, and I *think* works
> > better wrt precedence rules and allows a*-b. I might be overlooking stg also.
> 
> Using (0 - E) will work just as well in that regard. I was initially
> concerned about how to handle int-vs-float, but I've since confirmed
> that the interpreter expands types:
> 
> 	(int - int)   => int
> 	(int - float) => float
> 
> so subtracting the expression from integer zero should do the right
> thing.
> 
> > What does e.g. octave do? BTW I'd use yacc's %prec, but that's just laziness
> > of course.
> 
> It isn't parsing that's the issue, but what to insert into the parse
> tree once a negation has been recognised.
> 
> The attached patch inserts a y_term type between y_product and 
> y_atom, with the definition:
> 
> y_term:
> 		y_atom				{ $$ = $1; }
> 	|	'-' y_term {
> 		    $$ = sqpNewExpressionNode ( sqpOperatorCode("-"),
>  sqpNewValueNode ( NULL, 0, 0.0,  SQLP_I ), $2 ); 		} 	;
> 
> This allows for negations to be negated, i.e. --E is interpreted as
> -(-E). If this is not desired (I have no idea what the standard says
> about this), then the line:
> 
> 	|	'-' y_term {
> 
> would need to be changed to:
> 
> 	|	'-' y_atom {
> 
> -- 
> Glynn Clements <glynn at gclements.plus.com>
------- End of Original Message -------




More information about the grass-dev mailing list