Re: How to construct a BNF for a language mechanically and incrementally?

2009-12-29 Thread John Levine
>I just start reading the book "flex & bison Text Processing Tools" by >John Levine. Please excuse me if I ask some question that are >available somewhere in the book. When the grammar become huge, it >would be inconvenient put all BNFs in a single file. I'm wondering how >a huge grammar is handled

How to debug bison/flex program? usage of yyerror()

2009-12-29 Thread Peng Yu
I have the source files listed at the end of the message. I basically want to parse a file with only numbers (separated by spaces) and print the numbers out. It is an overkill to use bison/flex. But I just want to try how to use bison/flex. I need to understand how to debug the program. Could some

Re: How to construct a BNF for a language mechanically and incrementally?

2009-12-29 Thread Peng Yu
On Tue, Dec 29, 2009 at 2:49 AM, Hans Aberg wrote: > On 29 Dec 2009, at 03:54, 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?

Re: How to construct a BNF for a language mechanically and incrementally?

2009-12-29 Thread Peng Yu
On Tue, Dec 29, 2009 at 2:49 AM, Hans Aberg wrote: > On 29 Dec 2009, at 03:54, 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?

Name clash with token type BEGIN

2009-12-29 Thread Karl Landström
Hi, According to section 1.2 in the Bison manual "A terminal symbol that stands for a particular keyword in the language should be named after that keyword converted to upper case". When I follow this convention however, I get a syntax error and a warning in parser.h where the token type for t

Re: Name clash with token type BEGIN

2009-12-29 Thread August Karlstrom
Joel E. Denny wrote: [...] I agree. Of course, we're probably a few decades too late to change the default Flex behavior, which is inherited from Lex and specified by POSIX. However, it would be nice if Flex provided an option to avoid namespace pollution. (If there's something already, I mi

Re: Name clash with token type BEGIN

2009-12-29 Thread Joel E. Denny
On Tue, 29 Dec 2009, August Karlstrom wrote: > Joel E. Denny wrote: > > I'm guessing your parser.h is included in a scanner generated by Flex, which > > defines the macro BEGIN. > > Yes, that's the case. Do you know if there is there a way around this or do I > have to add a prefix to the token (

Re: Name clash with token type BEGIN

2009-12-29 Thread August Karlstrom
Joel E. Denny wrote: I'm guessing your parser.h is included in a scanner generated by Flex, which defines the macro BEGIN. Yes, that's the case. Do you know if there is there a way around this or do I have to add a prefix to the token (or all tokens for sake of consistency)? Obviously, the

Re: Name clash with token type BEGIN

2009-12-29 Thread Joel E. Denny
On Tue, 29 Dec 2009, August Karlstrom wrote: > When I follow this convention however, I get a syntax error and a > warning in parser.h where the token type for the keyword BEGIN is defined: > > error: expected identifier before ‘(’ token > warning: "BEGIN" redefined > > If I change > > %token B

Name clash with token type BEGIN

2009-12-29 Thread August Karlstrom
Hi, According to section 1.2 in the Bison manual "A terminal symbol that stands for a particular keyword in the language should be named after that keyword converted to upper case". When I follow this convention however, I get a syntax error and a warning in parser.h where the token type for th