> I'm new to Bison. I'm writing an interpreter for a lightweight C-like > language using flex and bison. My language has to support the *two* > types *int* and *float* used by the identifiers. > > My question is, do I have to write separate rules for both types in my > .y file, where each set of rules is dedicated for a given type, or do > I have to handle the differentiation between those types in the > grammatical actions associated with a unified set of rules for these > two types?
It's up to you. I don't think it's a good idea to use different types for the semantic value of a single symbol; `expr', in your example. Does this work? It wouldn't have occurred to me to try it. > Any ideas guys? Bison is extremely flexible, so it's really up to you. My approach in GNU 3DLDF is to use a set of non-terminals `numeric_primary', `numeric_secondary', `numeric_tertiary' and `numeric_expression'. This is based on the grammar of Donald Knuth's METAFONT language (except he wrote his parser from scratch). The semantic value for these symbols is `float' or `double' (depending on the value of a preprocessor macro). The 3DLDF grammar has a token `INTEGER' whose semantic value is `int', but it is replaced by a `float' or `double' in the "chain" of actions that "turn it into" a `numeric_<something>'. I hope I'm not overstepping the bounds here, but an idea that I would like to suggest is that you not write a C-like language. There must be thousands of them by now. It's a typical homework assignment for people studying computer science. There are plenty of languages waiting to be written with Bison that would really be useful. It would be a shame to write yet another "Appendix A" language. Laurence Finston _______________________________________________ help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison