Whenever I call yyparse()
with a valid file, I get a seg fault that seems to be caused by this line (around line 1789) of code:
if (yyss + yystacksize - 1 <= yyssp){
I arrived at this conclusion by printing debug messages before and after this line of code. The messages before this line were printed but those after this line weren't.
A strange thing is that if I call yyparse()
with an empty file, the error isn't thrown but it is thrown if the file has at least one character in it.
The parser itself has been compiled without any errors. What could be the reason/s behind this seg fault?
The parse file: https://gist.github.com/SamTebbs33/bffb72517f174af679ef
Debug message code:
cout << "before if" << endl;
if (yyss + yystacksize - 1 <= yyssp){
cout << "after if" << endl;
cout.flush();
The first debug message is printed 3 times before the error is thrown.
Edit: The error is actually being thrown in the switch statement when the 55 token is matched within the yyreduce label:
case 55:
#line 219 "grammar/grammar.y" /* yacc.c:1661 */
{
cout << "processing token 55" << endl;
(yyval.id) = new TIdentifier(*(yyvsp[0].string));
cout << "processed token 55" << endl;
}
#line 2228 "grammar/parser.cpp" /* yacc.c:1661 */
break;
Before the switch statement is reached, I print the integer value of the variable being switched and its value is 55, so the erroneous code should be within the above code, since "processed token 55" is not printed but "processing token 55" is printed. Below is the code for the TIdentifier constructor:
TIdentifier(std::string name) : name(name) {
}
This means that the error must be produced when dereferencing (yyvsp[0].string)