c - Makefile for sql parser... writing dependencies -
i'm implementing sql parser in lex , yacc, in use symbol table kept in separate .h file (sql.h) , in header file have functions declarations. definitions of these functions kept in .c file (sql.c). have included sql.h in sql.c, refer symbols , functions sql.h in both lex file(1.l) , yacc file(1.y).
the problem i'm not able write proper makefile this. i'm getting errors multiple declarations. include file , how write dependencies? please help. have searched solution i'm not getting it.....
update:
i compile code this:
lex 1.l yacc -d 1.y gcc lex.yy.c y.tab.c sql.c -ll -ly
i following errors after third command of gcc:
in file included 1.l:5: sql.h:17: warning: ‘sql’ initialized , declared ‘extern’ sql.h:18: warning: ‘sql_sel’ initialized , declared ‘extern’ 1.l: in function ‘maketable’: 1.l:80: warning: assignment incompatible pointer type in file included 1.y:7: sql.h:17: warning: ‘sql’ initialized , declared ‘extern’ sql.h:18: warning: ‘sql_sel’ initialized , declared ‘extern’ sql.c:3: error: redefinition of ‘sql’ sql.h:15: note: previous definition of ‘sql’ here sql.c:4: error: redefinition of ‘sql_sel’ sql.h:16: note: previous definition of ‘sql_sel’ here
sql.h:
#ifndef sql_h #define sql_h #include <string.h> #include <stdio.h> #include <stdlib.h> struct sym_table { char *token; char *value; struct sym_table *next; }; struct sym_select { char **cols; }; extern struct sym_table *sql = null; extern struct sym_select *sql_sel = null; void addsymbol(char *, char *); void print(struct sym_table *); void showtable(struct sym_table *); void maketable(struct sym_table *, int);
sql.c:
#include "sql.h" struct sym_table *sql = null; struct sym_select *sql_sel = null;
and definitions of functions declared in sql.h
1.l file:
%{ #include <stdio.h> #include <stdlib.h> #include "y.tab.h" #include "sql.h" int lineno=1; void maketable(struct sym_table *, int); %}
..... , othr lex file
1.y
%{ #include <stdio.h> #include <stdlib.h> #include <string.h> extern int lineno; extern void yyerror(char *); #include "sql.h" %}
.... , other yacc file data
can suggest me other way around this?
please post makefile. far understand there's problem code, not makefile. or try make 1.o
1.l
, different 1.o
1.y
.
normally dependencies should like:
1l.o: 1.l sql.h; # lex invocation 1y.o: 1.y sql.h; # bison invocation sql.o: sql.c sql.h; # cc invocation prog: 1l.o 1y.o sql.o; # ld invocation
probably need depend on tokens' declaration file.
edit: ah, need put definition of table 1 file, , declaration header. must first understand difference between declaration , definition in c. example if have following files:
aaa.h
int arr[]={1};
aaa.c
#include "aaa.h"
bbb.c
#include "aaa.h"
and try cc -o aaa aaa.c bbb.c
, multiple definition error. means, actual array must in 1 file, , in header should extern int arr[];
update:
you should remove setting null in sql.h. it's declaration there, there such , such variable somewhere. actual value assigned in sql.c.
Comments
Post a Comment