Hello,
I have a Bison code.
I want to declare a std::list<Circuit*> circuit_lists to be global so that I can add to this list once a certain grammar is found. But I always get an error when compiling "parser.y:28:1: error: ‘Circuit_lists’ does not name a type"
%debug
%{
/*--------------This part is normal C++ code that would appear before the Bison code-----*/
#include <stdio.h>
#include <string>
#include <iostream>
#include <fstream>
#include <stdexcept>
#include "Circuit.h"
#include <list>
#include <vector>
//declare the list of crcuit classes to add the elements to it
//this is also usefull when we add subcircuits. The first element in this list is always the main circtui
std::list<Circuit*>* Circuit_lists;
Circuit_lists->push_back(new Circuit); //I always get the error here
Circuit* MainCircuit = Circuit_lists->front();
extern"C" FILE *yyin;
void yyerror(constchar *str)
{
fprintf(stderr,"error: %s\n",str);
}
int yylex(void);
extern"C"
{
int yyparse(void);
int yywrap()
{
return 1;
}
int yylinno;
}
%}
%%
//Here I put my grammar
subcircuit_statment:
|SUBCKT STRING node_list{
circuit_lists.push_back(new Circuit);
}
;
%%
int main(int argc, char** argv)
{
int yydebug = 0;
FILE *file;
file = fopen(argv[1],"r");
if(!file) throw std::runtime_error("Can not open the file");
yyin = file;
yyparse();
//Start simulating the circuit
MainCircuit->start_analysis();
return 0;
}
You can't put statements outside of functions like that. Even if you could your code would still not work because Circuit_lists is a pointer and you haven't made it point to an object yet.
%debug
%{
/*--------------This part is normal C++ code that would appear before the Bison code-----*/
#include <stdio.h>
#include <string>
#include <iostream>
#include <fstream>
#include <stdexcept>
#include "Circuit.h"
#include <list>
#include <vector>
//declare the list of crcuit classes to add the elements to it
//this is also usefull when we add subcircuits. The first element in this list is always the main circtui
std::list<Circuit*> Circuit_lists;
Circuit_lists.push_back(new Circuit); //I always get the error here
Circuit* MainCircuit = Circuit_lists.front();
extern"C" FILE *yyin;
void yyerror(constchar *str)
{
fprintf(stderr,"error: %s\n",str);
}
int yylex(void);
extern"C"
{
int yyparse(void);
int yywrap()
{
return 1;
}
int yylinno;
}
%}
%%
//Here I put my grammar
subcircuit_statment:
|SUBCKT STRING node_list{
circuit_lists.push_back(new Circuit);
}
;
%%
int main(int argc, char** argv)
{
int yydebug = 0;
FILE *file;
file = fopen(argv[1],"r");
if(!file) throw std::runtime_error("Can not open the file");
yyin = file;
yyparse();
//Start simulating the circuit
MainCircuit->start_analysis();
return 0;
}