0

I need a parser (mainly for the "select" type of queries) and avoid the hassle of doing it from scratch. Does anybody know how to use the scan.l/gram.y of pgsql for this purpose? I've looked up pgpool too, but it seems similar. Currently, it might be very helpful if someone could give instructions to compile the parser (using the makefile provided maybe) without errors so that it can be supplied (valid?) queries and outputs the parse tree (in whatever form)!

3
  • Use Yacc? (yet another compiler compiler) Commented May 13, 2013 at 11:23
  • Without errors? If you're getting errors posting them will be helpful. Commented May 13, 2013 at 11:46
  • I've tried running flex on scan.l but the output c code doen't compile even after fixing header file issues. A part of the subsequently remaining errors is: kandarpksk@kandarpAspireRR:~/Documents/milestone_b$ gcc lex.core_yy.c -lfl In file included from scan.l:33:0: gram.y:161:2: error: unknown type name ‘core_YYSTYPE’ gram.y:169:2: error: unknown type name ‘JoinType’ gram.y:170:2: error: unknown type name ‘DropBehavior’ Commented May 13, 2013 at 11:55

2 Answers 2

1

You probably cannot take any file from postgres source tarball and compile it separately. Parser use internal OOP structures (implemented in C). But there is some possibility (not simple) - ecpg preprocessor try to transform PostgreSQL gram file to secondary gram file - and you can use same mechanism. It use a small utility parse.pl (it is part of PostgreSQL source code (src/postgresql/src/interfaces/ecpg/preproc))

Sign up to request clarification or add additional context in comments.

1 Comment

Apparently, it has been done according to postgresql.org/message-id/… but I couldn't figure out how to use it (pgpool) or its source.
0

PostgreSQL compiles the language parser using yacc. Presumably you could take the yacc files and create a compatible parser with very little effort. Note you must have flex and yacc installed to do this.

Note this is not taking a .c file from source and transplanting it into your system. All you are getting is the parser, not the planner or anything else.

Given the level of detail in the question no more detail can be possible. Perhaps you could start there and post another question when you get stuck.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.