1 /*-------------------------------------------------------------------------
4 * Main entry point/driver for PostgreSQL grammar
6 * Note that the grammar is not allowed to perform any table access
7 * (since we need to be able to do basic parsing even while inside an
8 * aborted transaction). Therefore, the data structures returned by
9 * the grammar are "raw" parsetrees that still need to be analyzed by
13 * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
14 * Portions Copyright (c) 1994, Regents of the University of California
17 * $Header: /cvsroot/pgsql/src/backend/parser/parser.c,v 1.58 2003/05/05 01:59:02 tgl Exp $
19 *-------------------------------------------------------------------------
24 #include "nodes/parsenodes.h"
25 #include "parser/gramparse.h"
26 #include "parser/parse.h"
27 #include "parser/parser.h"
28 #include "parser/parse_expr.h"
31 List *parsetree; /* result of parsing is left here */
33 static int lookahead_token; /* one-token lookahead */
34 static bool have_lookahead; /* lookahead_token set? */
39 * Given a query in string form, do lexical and grammatical analysis.
41 * Returns a list of raw (un-analyzed) parse trees.
44 raw_parser(const char *str)
48 parsetree = NIL; /* in case grammar forgets to set it */
49 have_lookahead = false;
59 if (yyresult) /* error */
67 * Intermediate filter between parser and base lexer (base_yylex in scan.l).
69 * The filter is needed because in some cases SQL92 requires more than one
70 * token lookahead. We reduce these cases to one-token lookahead by combining
71 * tokens here, in order to keep the grammar LR(1).
73 * Using a filter is simpler than trying to recognize multiword tokens
74 * directly in scan.l, because we'd have to allow for comments between the
82 /* Get next token --- we might already have it */
85 cur_token = lookahead_token;
86 have_lookahead = false;
89 cur_token = base_yylex();
91 /* Do we need to look ahead for a possible multiword token? */
95 /* UNION JOIN must be reduced to a single UNIONJOIN token */
96 lookahead_token = base_yylex();
97 if (lookahead_token == JOIN)
98 cur_token = UNIONJOIN;
100 have_lookahead = true;