Parsers: What are good ways to avoid conflicts in grammar?
-
I have a grammar file â https://github.com/itrelease/fubar-script/blob/jsast/src/grammar.js but I get conflicts â https://gist.github.com/2597616 and I don't really know how to solve this. If someone could explain me it would be helpful.
-
Answer:
These conflicts imply that your grammar is ambiguous. That is, for some strings the grammar can be parsed in multiple ways by the parser because at some point more than one rule is applicable during the derivation of the parse tree. This is obviously disastrous because it makes your compiler's behavior dependent on the parser itself, so the parser raises an error instead. A good way to design a grammar is to incrementally add features and resolve any conflicts that turn up. In your case, all the conflicts appear between the FormalParameterList and PrimaryExpressionNoBrace non-terminals whenever there is a THIS or IDENTIFIER token in the string. You should probably be able to resolve this by creating a new non-terminal that parses the conflicting cases and using it in both FormalParameterList and PrimaryExpressionNoBrace.
Shrey Banga at Quora Visit the source
Other answers
Avoiding ambiguity is not always possible and never easy, but luckily there are ambiguity detection methods and tools around. Have a look at my (ex-)colleagueâs publication list, his main focus of research was disambiguation of grammars: http://researchr.org/profile/basbasten/publications
Vadim Zaytsev
Related Q & A:
- What would be some good ways to advertise locally?Best solution by Yahoo! Answers
- What are good ways to save up for an iPod Touch?Best solution by wikihow.com
- What are good ways to promote my website?Best solution by Yahoo! Answers
- What are good ways to get the "Last Second Bid" on eBay successfully?Best solution by ebay.com
- What are good ways for personal fund raising?Best solution by wiki.answers.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.