How to remove ambiguity from a grammar | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to remove ambiguity from a grammar

Hello everyone Maybe this question not proper here but at least it related with the programming languages Anyway , if a grammar has an ambiguity how can removed is there any formal way for removing (like removing the left recursion in a grammar)?! Thanks

4th Mar 2020, 1:54 AM
Mohammed
4 Answers
+ 5
ambiguity come due to associativity or precedency so to remove ambiguity use left recursion for left associativity or right recursion for right associativity and also take care of precedency
5th Mar 2020, 5:39 PM
Nihal Gupta
Nihal Gupta - avatar
+ 1
Don't understand your question. What is "left recursion"? Do you have some examples?
4th Mar 2020, 2:02 AM
Gordon
Gordon - avatar
0
consider this grammar wich written in CFG E = E + T T = 0 | 1 | .. | 9 the E is keep looping (infinite) , there is a formal rule to solve this problem but I am just giving an example what I want is how can I solve the ambiguity
4th Mar 2020, 2:08 AM
Mohammed
0
I think you need the first to be able to terminate. E: E + T | T Or E: T + E | T Depending if you want left or right recursive. Are you using a parser generator tool to build a compiler?
4th Mar 2020, 10:01 AM
Jared Bird
Jared Bird - avatar