Why a regular grammar cannot be both left-recursive, and right-recursive?
by ajiten from LinuxQuestions.org on (#6DDJ5)
It is stated that a regular grammar can be either left-linear, or right-linear; but not both.
Want to understand why?
Let us take the below grammar, which is having left recursion, in all except the rule for derivation of the non-terminal symbol: factor:
Code:expr->expr+term | expr - term | term
term-> term*factor | term/factor | factor
factor -> digit factor | digit
digit -> 0|1|2|3|4|5|6|7|8|9Want to understand why the parse of arithmetic expressions, as per the above grammar is impossible; say for the string: 2*3*5-112+2+3.
Please give some insights.
Want to understand why?
Let us take the below grammar, which is having left recursion, in all except the rule for derivation of the non-terminal symbol: factor:
Code:expr->expr+term | expr - term | term
term-> term*factor | term/factor | factor
factor -> digit factor | digit
digit -> 0|1|2|3|4|5|6|7|8|9Want to understand why the parse of arithmetic expressions, as per the above grammar is impossible; say for the string: 2*3*5-112+2+3.
Please give some insights.