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)!
-
Use Yacc? (yet another compiler compiler)Neil– Neil2013-05-13 11:23:26 +00:00Commented May 13, 2013 at 11:23
-
Without errors? If you're getting errors posting them will be helpful.Jakub Kania– Jakub Kania2013-05-13 11:46:20 +00:00Commented 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’Kandarp Khandwala– Kandarp Khandwala2013-05-13 11:55:03 +00:00Commented May 13, 2013 at 11:55
2 Answers
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))
1 Comment
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.