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...
An oversimplification of the D BNF expression section has
expressions threaded. Here is a grossly simplified example:
----------------------------------------------------------------
Expression:
AddExpression
AddExpression:
MulExpression
AddExpression + MulExpression
AddExpression - MulExpression
MulExpression:
PrimaryExpression
MulExpression * UnaryExpression
MulExpression / UnaryExpression
PrimaryExpression:
Identifier
NumericLiteral
----------------------------------------------------------------
The BNF seems to imply:
All expressions are AddExpressions
All AddExpressions are MulExpressions
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
AddExpression
PrimaryExpression:
Identifier
NumericLiteral
MulExpression:
Expression * Expression
Expression / Expression
AddExpression:
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
instead of the second. Thanks!
http://acm.zju.edu.cn/maxiao/major/compile/article/yaccforc.htm
http://www.cs.uiowa.edu/~fleck/JavaBNF.htm
Jan 04 2005
---------------------------------------------------------------- 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








"Ben Hinkle" <ben.hinkle gmail.com>