1

I got an assignment to write my own RAM-based DBMS. I wrote all the crud functions in crud.c and included the header file crud.h in yacc file. But I'm getting errors on compilation. Here is my code:

sql_parser.y file:

%{
#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

when I run make I get the following errors:

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

I get unknown type name errors.

What is the right way to compile and link the yacc file?

SATHWIK MATSA
  • 43
  • 3
  • 6

0 Answers0