[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to write the BNF
From: |
Sharan Basappa |
Subject: |
Re: How to write the BNF |
Date: |
Tue, 11 Mar 2008 18:58:06 +0530 |
Thanks. On the last part, I believe the keywords would also be
generally categorized as tokens/terminals.
Suppose I have come up with a new language and want to give a formal
explanation to it.
For items like if, else, main I categorize them as keywords and then I
categorize
if, else, main, {, } as terminal tokens. Do you think this is a good
way of explaining the
language
On Tue, Mar 11, 2008 at 2:35 PM, Hans Aberg <address@hidden> wrote:
>
> 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
>
>
>