List:Internals« Previous MessageNext Message »
From:Sergei Golubchik Date:April 8 2006 9:36pm
Subject:Re: parsing SQL expressions
View as plain text  
Hi!

On Apr 08, Eric Prud'hommeaux wrote:
> Looking at sql/sql_yacc.yy , I see that
> thd->lex->current_select->expr_list contains a lot of the state while
> parsing expressions. I'm trying to emulate this use in sparqlParser.
> Can someone explain roughly how this is used?

It's used to accumulate the list of expressions, and used in rules like

udf_expr_list2, expr_list, ident_list, and so on.
E.g.

expr_list:
        { Select->expr_list.push_front(new List<Item>); }
        expr_list2
        { $$= Select->expr_list.pop(); };

and expr_list2 adds its elements to the list on top of the stack.
expr_list rule is used, for example, for functions that accept an
arbitrary number of arguments (such as. IN(...)).

Also, boolean AND and OR are implemented internally not as binary
operations but as functions of many arguments: OR(arg1, arg2, ...), and
same for AND. So expr_list is also ised for AND and OR.

> Is it dependent on thd->lex->current_select->parsing_place ?

Hardly. It doesn't look like it is.

> Does it get put on a stack when the parser encounters ()s ?

No, it's not for expressions or subexpressions, it's for _lists_ of
expressions. E.g. for

  WHERE a=9 OR x > 4 AND y < 6 AND z IN (1,2,3)

a first list is put on the stack for OR, the second - for AND,
and the third - for IN.

Regards,
Sergei

-- 
   __  ___     ___ ____  __
  /  |/  /_ __/ __/ __ \/ /   Sergei Golubchik <serg@stripped>
 / /|_/ / // /\ \/ /_/ / /__  MySQL AB, Senior Software Developer
/_/  /_/\_, /___/\___\_\___/  Kerpen, Germany
       <___/  www.mysql.com
Thread
parsing SQL expressionsEric Prud'hommeaux8 Apr
  • Re: parsing SQL expressionsSergei Golubchik8 Apr