parsing - Difference between: 'Eliminate left-recursion' and 'construct an equivalent unambiguous grammar' -


for example:

r → r bar r|rr|r star|(r)|a|b 

construct equivalent unambiguous grammar:

r → s|rbars s→t|st t → u|tstar u→a|b|(r) 

how eliminate left-recursion r → r bar r|rr|r star|(r)|a|b?

what's different between eliminate left-recursion , construct equivalent unambiguous grammar?

an unambiguous grammar 1 each string in language, there 1 way derive grammar. in context of compiler construction problem ambiguous grammar it's not obvious grammar parse tree given input string should be. tools solve using rules resolving ambiguities while other require grammar unambiguous.

a left-recursive grammar 1 derivation given non-terminal can produce same non-terminal again without first producing terminal. leads infinite loops in recursive-descent-style parsers, no problems shift-reduce parsers.

note unambiguous grammar can still left-recursive , grammar without left recursion can still ambiguous. note depending on tools, may need remove ambiguity, not left-recursion, or may need remove left-recursion, not ambiguity (though unambiguous grammar preferable).

so difference eliminating left recursion , ambiguity solve different problems , necessary in different situation.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -