help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to write the BNF


From: Hans Aberg
Subject: Re: How to write the BNF
Date: Tue, 11 Mar 2008 10:05:42 +0100


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






reply via email to

[Prev in Thread] Current Thread [Next in Thread]