Re: Reduce/Reduce conflict in Algol60 grammar

SM Ryan <wyrmwif@tsoft.org>
11 Oct 2006 23:22:57 -0400

          From comp.compilers

Related articles
Reduce/Reduce conflict in Algol60 grammar leonardo@dcc.ufmg.br (Leonardo Teixeira Passos) (2006-10-10)
Re: Reduce/Reduce conflict in Algol60 grammar luvisi@andru.sonoma.edu (Andru Luvisi) (2006-10-11)
Re: Reduce/Reduce conflict in Algol60 grammar idknow@gmail.com (idknow@gmail.com) (2006-10-11)
Re: Reduce/Reduce conflict in Algol60 grammar wyrmwif@tsoft.org (SM Ryan) (2006-10-11)
Re: Reduce/Reduce conflict in Algol60 grammar cfc@shell01.TheWorld.com (Chris F Clark) (2006-10-12)
Re: Reduce/Reduce conflict in Algol60 grammar wyrmwif@tsoft.org (SM Ryan) (2006-10-13)
Re: Reduce/Reduce conflict in Algol60 grammar kenrose@nc-sys.com (Ken Rose) (2006-10-14)
Re: Reduce/Reduce conflict in Algol60 grammar bobduff@shell01.TheWorld.com (Robert A Duff) (2006-10-14)
Re: Reduce/Reduce conflict in Algol60 grammar DrDiettrich1@aol.com (Hans-Peter Diettrich) (2006-10-14)
Re: Reduce/Reduce conflict in Algol60 grammar cfc@shell01.TheWorld.com (Chris F Clark) (2006-10-15)
| List of all articles for this month |

From: SM Ryan <wyrmwif@tsoft.org>
Newsgroups: comp.compilers
Date: 11 Oct 2006 23:22:57 -0400
Organization: Quick STOP Groceries
References: 06-10-036
Keywords: algol60, parse
Posted-Date: 11 Oct 2006 23:22:57 EDT

# primary ::=
# variable |


# boolean_primary ::=
# variable |


# Note the common part between primary and boolean_primary, which leads to
# the conflict. The only way that I could resolve this was to merge arithmetic_expression and


The problem is this is a ambiguous context free grammar, therefore
not LR(k). To reduce the variable you need to match it to the
declaration elsewhere to decide if it is a Boolean or arithmetic
variable.


So, yes, you instead use a larger grammar that includes erroneous
programs, and then use some post parsing work to enforce context
sensitive rules.


# [You could try building types into the grammar like boolean_variable
# and boolean_function_designator, but it's not going to be pretty. -John]


Unless you use a two-level grammar, you cannot write enough productions.


--
SM Ryan http://www.rawbw.com/~wyrmwif/


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.