I am writing a bison file for parsing. In a declared grammar rule, I'm trying to create a unique_ptr pointing to a syntax tree node (DeclAST) that contains multiple symbol table entries. However, an error message was encountered:
parser.y:73:19: error: invalid use of ‘class std::unique_ptr<DeclAST>’
73 |$$ = std::make_unique<DeclAST>(syms,2,$3);
The code at line 73 of parser.y and the context-sensitive code are as follows:
ConstDecl:{declare =1;} CONST Btype COnstDefs{declare=0;} SEMI
{
$$ = std::make_unique<DeclAST>(syms,2,$3);
...
}
I have made it clear that the node type of ConstDecl is DeclAST:
%type< unique_ptr<DeclAST> > ConstDecl
%type< int > Btype
For Btype, the corresponding code in parser.y is:
Btype: ICONST {$$ = INT_TYPE;}
| FCONST {$$ = FLOAT_TYPE;}
Also:
#define INT_TYPE 258
#define FLOAT_TYPE 259
#define SIZE 100
I checked my definition of DeclAST:
class DeclAST
{
Symtab** names;
int names_count;
int data_type;
public:
DeclAST(Symtab** s, int nsc, int dty)
:names(s), names_count(nsc), data_type(dty);
};
For Symtab:
Symtab** syms = (Symtab**) malloc(SIZE*sizeof(Symtab*));
I also included the header file . All things seem correct.
Any detailed help will be appreciated.