I have spent all of yesterday and 7x hours today trying to find a definitive answer to a question in an assignment. I have watched hours of lectures on BNF and EBNF but none have addressed my question. I have learned loads though :)

I hope somebody can point the way:

Given this Grammar

G = {N, T, S, P} 
T = {a, b, c, - , ×} 
N = {<goal>, <expr>, <term>, <factor>} 
S = <goal> 
P = 
<goal> ::= <expr> 
<expr> ::= <term> | <expr> - <term> 
<term> ::= <factor> | <term> × <factor> 
<factor> ::= a|b|c

and then change the rules to:

<goal> ::= <expr>
<expr> ::= <term> | <term> - <expr> 
<term> ::= <factor> | <factor> × <term>
<factor> ::= a|b|c

What effect does it have on the production?

All I can see is it changes the LHS recursion to RHS recursion. I'd really like to know what I'm missing.

Other questions in the assignment changed the order of the rules which I answered: Rules that are lower in the cascade of productions have higher precedence.

有帮助吗?

解决方案

After consulting with the lecturer I confirmed the only difference is: it changes the LHS recursion to RHS recursion.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top