Re: Postgresql parser

From: Florian Pflug <fgp(at)phlo(dot)org>
To: andurkar <andurkarad10(dot)comp(at)coep(dot)ac(dot)in>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Postgresql parser
Date: 2011-09-27 11:28:00
Message-ID: 10C51910-65A4-4ED0-BA7D-B197770B8BD8@phlo.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sep27, 2011, at 10:44 , andurkar wrote:
> Currently I am working on Postgresql... I need to study the gram.y and
> scan.l parser files...since I want to do some qery modification. Can anyone
> please help me to understand the files. What should I do ? Is there any
> documentation available ?

scan.l defines the lexer, i.e. the algorithm that splits a string (containing
an SQL statement) into a stream of tokens. A token is usually a single word
(i.e., doesn't contain spaces but is delimited by spaces), but can also be
a whole single or double-quoted string for example. The lexer is basically
defined in terms of regular expressions which describe the different token types.

gram.y defines the grammar (the syntactical structure) of SQL statements,
using the tokens generated by the lexer as basic building blocks. The grammar
is defined in BNF notation. BNF resembles regular expressions but works
on the level of tokens, not characters. Also, patterns (called rules or productions
in BNF) are named, and may be recursive, i.e. use themselves as sub-patters.

The actual lexer is generated from scan.l by a tool called flex. You can find
the manual at http://flex.sourceforge.net/manual/

The actual parser is generated from gram.y by a tool called bison. You can find
the manual at http://www.gnu.org/s/bison/.

Beware, though, that you'll have a rather steep learning curve ahead of you
if you've never used flex or bison before.

best regards,
Florian Pflug

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2011-09-27 12:24:47 Re: heap_update temporary release of buffer lock
Previous Message Florian Pflug 2011-09-27 11:06:39 Re: bug of recovery?