I am currently working on a verilog parser using bison and flex as the tokenizer. My grammar works fine and now my goal is to store the data collected in a database. (If you don't know what verilog is, it doesn't really matter but you can find info here : http://www.verilog.com/VerilogBNF.html)
I am currently stuck on getting the token values. My grammar mainly consists of strings and some numbers.
I browsed the internet and find usefull stuff that lead me tu write this kind of lex rules :
[A-Za-z_]+[A-Za-z0-9_$]* {
lline = yylineno;yylval.str = strdup(yytext);
return K_IDENTIFIER;
}
In my bison input file .y I made some adjustments that are
#define YYSTYPE char*
....
%union {char* str;
double val;
}
%token<str>K_IDENTIFIER
...
beginning of the grammar rules
Now, when i have a grammar rule that has a K_IDENTIFIER in it such as
module : K_MODULE K_IDENTIFIER list_of_ports_parameters K_POINTVIRG
{cout << "the value of K_IDENTIFIER is :"<< $2.str << endl;}
list_of_module_itemsE
K_ENDMODULE
fdsfds
As you can see, i would like to print the value (which is a string) of K_IDENTIFIER. This is just an example to help me understand the mechanism behind that because later i will create some c++ object and fill information in them depending on what i read.
If you need more code to see my problem, feel free to ask. thank you