Red Hat Database: Administrator and User's Guide | ||
---|---|---|
Prev | Chapter 10. Overview of PostgreSQL Architecture and Internals | Next |
The parser stage consists of two parts:
The parser defined in gram.y and scan.l is built using the UNIX tools yacc and lex.
The transformation process does modifications and augmentations to the data structures returned by the parser.
The parser has to check the query string (which arrives as plain ASCII text) for valid syntax. If the syntax is correct, a parse tree is built up and handed back; otherwise, an error is returned. The UNIX tools lex and yacc are used for this implementation.
The lexer, defined in the file scan.l, is responsible for recognizing identifiers, SQL keywords, and so on. The lexer generates a token for every keyword or identifier, and gives it to the parser.
The parser, defined in the file gram.y, consists of a set of grammar rules and actions that are executed whenever a rule is fired. These actions build up the parse tree.
The transformation process takes the tree handed back by the parser as input and steps recursively through it. It then transforms the tree into the internal formula used by the database backend.