On Mon, 2009-12-28 at 20:54 -0600, Peng Yu wrote: > It seems to me that to use bison I have to have a BNF first. I'm > reading Programming Language Pragmatics 3rd Ed (PLP3). What is not > clear to me is that how to construct the BNF for a language? Based on > my reading of PLP3, I haven't found a formal way to construct BNF. > What I understand is that, to construct a BNF, I'll have to think > about some examples written in the language and write the BNF based on > my experience. > > A language definition is usually evolving. It is not clear to me > whether it always affects the BNF incrementally if the language is > changed little by little. > > Please excuse me if my questions have been answered by some books or > previous discussions. Could somebody let me know how to details the > two issues? >
Hey Yeah I understand what you mean, it can be confusing and frustrating, but designing a language isn't an easy thing to do I've been working at my language for about a year now. What i will say, when writing a bnf for a language or your bison grammar always test try and test. When working with your basic implementation of a language you can get caught up in the runtime and your grammar can be flawed but really you need to spend most of your time writing in your language and thinking about the syntax. Getting a decent book on language theory can help with this, since writing grammar in bison all the time can be time consuming until you have your self a formalized IR for your language. So at the moment when designing semantics or constructs in my language i tend to focus on what would an IR look like for this and then design the grammar on paper then in bison. http://crules.org/doku.php?id=hacking#adding_to_the_language Since if you can build yourself a decent and efficient IR then you know you can evaluate it correctly, if not you need to think about the syntax more and test again until you get a decent IR once you have that then you know you can get your self a grammar. I have some info on this here, but it isn't written terribly well same on my blog the latest post is talking about IR http://redbrain.co.uk . I think it was you i replied to on comp.compilers that language theory book is nice introduction that and the dragon book is great helped me a lot but i think they could have done a better job in many parts but hey i wouldn't have any idea what i am doing with out it :). PS i think reading about other grammars in detail can help a lot since it makes you think about the problem differently which is what can help, since there isn't a 'procedure' to define a language since a language can be anything you have to design it. I think it just comes with practice more than anything took me ages to get used to language design. My first compiler project I focused on the back-end and it was just more a test to build a code generator for myself though it was pretty broken I just wanted to see what can be involved in a basic c compiler since the c language is so well defined its easy to build yourself a limited subset of the language's grammar quite quickly. Hope this helps! --Phil
signature.asc
Description: This is a digitally signed message part
_______________________________________________ help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison