Can somebody explain how the 'parsetree' in the parser( ) function get populated? What I saw is just a NIL. And it is not touched else where in this file.

This file is src/backend/parser/parser.c

Thanks!

Bin

/*
 * parser
 *  Given a query in string form, and optionally info about
 *  parameter types, do lexical and syntactic analysis.
 *
 * Returns a list of raw (un-analyzed) parse trees.
 */
List *
parser(StringInfo str, Oid *typev, int nargs)
{
 int   yyresult;

 parsetree = NIL;   /* in case parser forgets to set it */
 have_lookahead = false;

 scanner_init(str);
 parser_init();
 parse_expr_init();
 parser_param_set(typev, nargs);

 yyresult = yyparse();

 scanner_finish();
 clearerr(stdin);

 if (yyresult)    /* error */
  return NIL;

 return parsetree;
}







Can somebody explain how the 'parsetree' in the 
parser( ) function get populated? What I saw is just a NIL. And it is not 
touched else where in this file.
 
This file is 
src/backend/parser/parser.c
 
Thanks!
 
Bin
 
/* * parser *  Given a 
query in string form, and optionally info about *  parameter 
types, do lexical and syntactic analysis. * * Returns a list 
of raw (un-analyzed) parse trees. */List *parser(StringInfo 
str, Oid *typev, int 
nargs){ int   yyresult;
 
 parsetree = NIL;   /* in case 
parser forgets to set it */ have_lookahead = false;
 
 scanner_init(str); parser_init(); parse_expr_init(); parser_param_set(typev, 
nargs);
 
 yyresult = yyparse();
 
 scanner_finish(); clearerr(stdin);
 
 if (yyresult)    /* error 
*/  return NIL;
 
 return parsetree;}
Mon, 11 Oct 2004 18:13:43 -0400
"Bin Liu" <bliu@ece.gatech.edu>
Question about Parser()
On Tue, 2004-10-12 at 08:13, Bin Liu wrote:
> Can somebody explain how the 'parsetree' in the parser( ) function get
> populated? What I saw is just a NIL. And it is not touched else where
> in this file.

"parsetree" is a global variable; it is defined in parser.c, but
declared (via extern) in gram.y. gram.y constructs the parsetree (via
yacc) and delivers the raw parsetree back to parser() by assigning to
"parsetree" (see the "stmtblock" production in gram.y, for example).

-Neil



Wed, 13 Oct 2004 14:05:53 +1000
Neil Conway <neilc@samurai.com>
Re: Question about Parser()