## digitalmars.D - D doc BNF question

• parabolis (43/43) Jan 04 2005 An oversimplification of the D BNF expression section has
• Ben Hinkle (2/6) Jan 04 2005 unambiguous operator precedence. The expression a+b*c must parse as a+(b...
parabolis <parabolis softhome.net> writes:
```An oversimplification of the D BNF expression section has
expressions threaded. Here is a grossly simplified example:
----------------------------------------------------------------
Expression:

MulExpression

MulExpression:
PrimaryExpression
MulExpression * UnaryExpression
MulExpression / UnaryExpression

PrimaryExpression:
Identifier
NumericLiteral
----------------------------------------------------------------
The BNF seems to imply:

All MulExpressions are PrimaryExpressions

Which seems counter-intuitive to me. I am wondering why the
recursive definition is used instead of something like this:
----------------------------------------------------------------
Expression:
PrimaryExpression
MulExpression

PrimaryExpression:
Identifier
NumericLiteral

MulExpression:
Expression * Expression
Expression / Expression

Expression + Expression
Expression - Expression
----------------------------------------------------------------
The same threaded style BNF is used in the BNF I found for both
ANSI C and Java. I would like to understand why the first

http://acm.zju.edu.cn/maxiao/major/compile/article/yaccforc.htm
http://www.cs.uiowa.edu/~fleck/JavaBNF.htm
```
Jan 04 2005
"Ben Hinkle" <ben.hinkle gmail.com> writes:
``` ----------------------------------------------------------------
The same threaded style BNF is used in the BNF I found for both ANSI C and
Java. I would like to understand why the first instead of the second.
Thanks!

unambiguous operator precedence. The expression a+b*c must parse as a+(b*c)
and not (a+b)*c.
```
Jan 04 2005