Re: [CS3304_1381] EBNF mistake?

New Message Reply About this list Date view Thread view Subject view Author view

Stephen Edwards (edwards@CS.VT.EDU)
Mon, 24 Apr 2000 08:58:19 -0400


Message-ID:  <390444EB.7F04275B@cs.vt.edu>
Date:         Mon, 24 Apr 2000 08:58:19 -0400
From: Stephen Edwards <edwards@CS.VT.EDU>
Subject:      Re: [CS3304_1381] EBNF mistake?

Sean Cooper wrote:
>
> Is it just me or is the EBNF not 100% accurate?
>
> expression -> term { ( + / - ) term }

Patrick Raphael was right in replying that the EBNF is accurate.

> shouldn't it be
> expression -> term { (+/-) expression }

This makes the grammar ambiguous. If we were using plain BNF instead
of EBNF, you might want to write this rule as:

<expression> --> <term> + <expression>
             | <term> - <expression>

(Note that this does cause associativity problems, though.)
The use of {}'s in the EBNF version does away with the recursive
reference in the rule.

> because if you follow the given definition 1+1+1 doesn't work... and 1-1-1
> doesn't work...

Both of these sentences are legal under the original grammar, and both
are ambiguous under your proposed modification.

As discussed in class, when using EBNF, placing a recursive
reference to the rule you are defining inside {}'s is almost
certain to lead to ambiguity or other problems. {}'s are analogous
to iteration in procedural programming, while self-referencing nonterminals
are analogous to recursive calls. For any given task involving
repetition, you can use one or the other, but trying to use both
at the same time for one repetitive task is likely to lead to
problems.

                                -- Steve

--
Stephen Edwards            641 McBryde Hall          Dept. of Computer Science
e-mail      : edwards@cs.vt.edu           U.S. mail: Virginia Tech (VPI&SU)
office phone: (540)-231-5723                         Blacksburg, VA  24061-0106
-------------------------------------------------------------------------------


New Message Reply About this list Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b3 on Mon Apr 24 2000 - 08:58:24 EDT