我被分配编写自己的基于RAM的DBMS。我在crud.c
中编写了所有crud函数,并在yacc文件中包含了头文件crud.h
。但是我在编译时遇到错误。这是我的代码:
sql_parser.y文件:
%{
#include <stdio.h>
#include "crud.h" // my header file
extern FILE* yyin;
databasePtr root = NULL;
%}
%token R_OP_1 R_OP_2 EQ INSERT INTO VALUES CREATE DEFAULT PRIMARY KEY NOT NONE
%union{
struct s {tablePtr m_table; int type; char* name; attrPtr m_attr; listPtr m_list;} db_object;
}
%token <db_object> TABLE ID TYPE_SPECIFIER LITERAL
%type <db_object> CREATE_TABLE CONSTRAINT CONSTRAINTS ATTR_LIST COL_LIST VAL_LIST
%%
..
..
Makefile:
CC=cc
all:parser
y.tab.c y.tab.h: sql_parser.y
yacc -d sql_parser.y
lex.yy.c:sql_lexer.l y.tab.h
lex sql_lexer.l
parser: lex.yy.c y.tab.c crud.c
$(CC) -o parser y.tab.c lex.yy.c crud.c -ly -ll -w
clean:
rm -f *.o parser lex.yy.c y.tab.c y.tab.h
当我运行make时,出现以下错误:
yacc -d sql_parser.y
lex sql_lexer.l
cc -o parser y.tab.c lex.yy.c crud.h crud.c -ly -ll -w
In file included from sql_lexer.l:2:0:
sql_parser.y:11:12: error: unknown type name ‘tablePtr’
struct s {tablePtr m_table; int type; char* name; attrPtr m_attr; listPtr m_list;} db_object;
^~~~~~~~
sql_parser.y:11:52: error: unknown type name ‘attrPtr’
struct s {tablePtr m_table; int type; char* name; attrPtr m_attr; listPtr m_list;} db_object;
^~~~~~~
sql_parser.y:11:68: error: unknown type name ‘listPtr’
struct s {tablePtr m_table; int type; char* name; attrPtr m_attr; listPtr m_list;} db_object;
^~~~~~~
Makefile:12: recipe for target 'parser' failed
make: *** [parser] Error 1
我遇到unknown type name
错误。
编译和链接yacc文件的正确方法是什么?