Thread: Question about Parser()
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;
* 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;
have_lookahead = false;
scanner_init(str);
parser_init();
parse_expr_init();
parser_param_set(typev, nargs);
parser_init();
parse_expr_init();
parser_param_set(typev, nargs);
yyresult = yyparse();
scanner_finish();
clearerr(stdin);
clearerr(stdin);
if (yyresult) /* error */
return NIL;
return NIL;
return parsetree;
}
}
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