On 10 Mar 2008, at 15:55, Sharan Basappa wrote:
I would like to know how to write BNF for code blocks that have
optional block enclosing symbols like {}
For example, the following statements are both valid:
if () $printf();
if()
{
func1;
func2;
}
How to I specify that {} are optional when number of statement is
just one.
One way to do it, is to write it as EBNF, and then use rewrite rules
to BNF. Search for "EBNF" here
http://lists.gnu.org/pipermail/bug-bison
Or directly
AorNone:
/* empty */
| A
The empty expansion has no token - I just put in a comment for
clarification. Also see the Bison manual.
Also, when I write a BNF for a new lanugage, the words that are
reserved are categorized as keywords.
What about symbols like {} etc. What are they categorized as?
In Bison, they are called "tokens", "terminals, or "grammar
constants". This includes also defined variables and such -
everything that comes directly from the lexer (generated by say
Flex). Bison parses only tokens.
Hans Aberg
_______________________________________________
help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison