SQL parsing is implemented using ANTLR4. See Grammars for more details on how the grammars are created and updated.
SQL Surveyor is implemented as a series of listeners (one for each SQL dialect that is supported).
ANTLR4 parses the input SQL. The relevant listener for the SQL Dialect is then attached to the parse tree and the tree is walked. As relevant tokens are visited in the ParseTree, the listener adds the correct values (queries, columns, tables, etc.) to a ParsedSql object.