I am new to c/c++.
I've tried the following ways to use the container type as the type for the semantic value, but none of them worked.
Declare the type in %union:
// in parser.y
#include <vector>
%union {
std::vector<int> *myVectorType;
}
Result of the make command:
For the above try, the error occurs whether myVectorType is used in %type or not.
Use vector in %type or %nterm directly.
I found a similar issue that asked by the past student and followed the official documentation to do this.
// in parser.y
#include <vector>
%type <std::vector<int>> TerminalList; // or use %nterm
TerminalList:
Epsilon {
// just empty
// or $$ = { 1, 2, 3 };
}
|
TerminalList Terminal {
$$ = $1
$$.push_back(1);
// or $$.push_back($2);
// or $$->push_back(1);
// or $$->push_back($2);
}
;
Result of the make command:
For the above try, although the official documentation shows that it's necessary to add the %language="c++" to enable C++ in bison, but when I tried to add %language="c++" to my parser, I got lots of errors about the yy founctions and no way to debug by my self or do more things.
It would be great that if you could give me some hints.
Thank you in advance!
Additional information:
To make sure the c++ STL works correctly in the general code block, I add the following code to the int main(int argc, const char *argv[]) in parser.y and confirmed it worked:
Hi TA,
I am new to c/c++. I've tried the following ways to use the container type as the type for the semantic value, but none of them worked.
Declare the type in
%union
:Result of the
make
command:Use
vector
in%type
or%nterm
directly. I found a similar issue that asked by the past student and followed the official documentation to do this.Result of the
make
command:It would be great that if you could give me some hints. Thank you in advance!
Additional information:
To make sure the c++ STL works correctly in the general code block, I add the following code to the
int main(int argc, const char *argv[])
inparser.y
and confirmed it worked: