I found a question while studying compilers :-

Given a grammar E->E+E/E×E/number

The above grammar is fed to a YACC with semantic rules for parsing. What will be the action of the YACC.

1) it detects recursion and eliminates recursion.

2) it detects RR conflict and resolves

3) it detects SR conflict and resolves in favour of Shift over Reduce action

4) it detects SR conflict and resolves in favour of reduce over shift action

The answer given is option 3. But I have read that LALR parser cannot parse ambiguous grammar, while the above grammar is ambiguous.

A) So how can YACC(which is a LALR parser) parse the given grammar?

B) What about other ambiguous grammar, I.e. can YACC parse all the ambiguous grammars?

  • 1
    $\begingroup$ Why don't you feed this grammar to YACC and see what happens? $\endgroup$ – Yuval Filmus Apr 3 '18 at 12:28
  • 1
    $\begingroup$ This seems to be a question about the behaviour of a specific piece of software (YACC), rather than a question about the principles of computer science. $\endgroup$ – David Richerby Apr 3 '18 at 12:28
  • $\begingroup$ @YuvalFilmus but can the YACC parse any given ambiguous grammar? i know it can resolve the SR and RR conflicts but can it parse any given ambiguous grammar? and if it is ambiguous and it is parsed, is the resulted parse tree the same as the language of the grammar? $\endgroup$ – John P Apr 3 '18 at 12:49
  • $\begingroup$ Once again, I suggest trying it out and see what happens. $\endgroup$ – Yuval Filmus Apr 3 '18 at 13:01
  • 1
    $\begingroup$ Cross-posted: stackoverflow.com/q/49628199/781723, cs.stackexchange.com/q/90163/755. Please do not post the same question on multiple sites. Each community should have an honest shot at answering without anybody's time being wasted. $\endgroup$ – D.W. Apr 3 '18 at 22:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.