Related articles |
---|
Dangling else borneq@nborneq.nospam.pl (borneq) (2006-02-19) |
Re: Dangling else haberg@math.su.se (2006-02-19) |
Re: Dangling else wyrmwif@tsoft.org (SM Ryan) (2006-02-24) |
Re: Dangling else rsc@swtch.com (Russ Cox) (2006-02-24) |
Re: Dangling else rsc@swtch.com (Russ Cox) (2006-02-24) |
Re: Dangling else wyrmwif@tsoft.org (SM Ryan) (2006-03-05) |
Re: Dangling else wyrmwif@tsoft.org (SM Ryan) (2006-03-05) |
[12 later articles] |
From: | "borneq" <borneq@nborneq.nospam.pl> |
Newsgroups: | comp.compilers |
Date: | 19 Feb 2006 02:01:57 -0500 |
Organization: | tp.internet - http://www.tpi.pl/ |
Keywords: | parse, question, yacc |
Posted-Date: | 19 Feb 2006 02:01:57 EST |
I have grammar:
S->ibtSeS
S->ibtS
S->s
where i mean 'if', t:'then', e:'else'
b:boolean expression, S - general statement, s - statement without
"if..then,if..then..else"
(upper case - nonterminals, lowe case - terminals)
I have 9 states:
I0:
Z->.S
S->.ibtSeS
S->.ibtS
S->.S
I1:
Z->S.
I2:
S->i.btSeS
S->i.btS
I3:
S->s.
I4:
S->ib.tSeS
S->ib.tS
I5:
S->.ibtSeS
S->ibt.SeS
S->.ibtS
S->ibt.S
S->.S
I6:
S->ibtS.eS
S->ibtS.
I7:
S->.ibtSeS
S->ibtSe.S
S->.ibtS
S->.S
I8:
S->ibtSeS.
In state 6 I have conflict: 'e' cause reduction or shift.
for common languages I think it should choose shift.
In manual.pdf in dyacclex-1.4.zip is simple:
- in a shift/reduce conflict, Delphi Yacc chooses the shift action
- in a reduce/reduce conflict, Delphi Yacc chooses reduction
of the first grammar rule.
But - how resolve conflict depends on operator precedence and left/right
association? In nice site:htm:
http://lambda.uta.edu/cse5317/notes/node21.html we have:
"The idea is that if the lookahead has higher precedence
than the production currently used, we shift..
If the lookahead has the same precedence as that of the current production
and is left associative, we reduce, otherwise we shift
What it means in my case? lookahead 'e' has higher precedence
than the production S->ibtS ??
Another rules used to resolving conflict:
in C.y (Dcg.zip by Mike Lischke):
/* Add precedence rules to solve dangling else s/r conflict */
%nonassoc IF
%nonassoc ELSE
in z Fparser.y (FParser1.zip Robert Zierer, mwdelpar.zip Martin Waldenburg )
and delphiYacc.y (DelpYacc.zip, DelpPars.zip)
%right _THEN_ _ELSE_ /* resolve dangling else */
What action I must do accordingly to %right,%left and %nonassoc?
Return to the
comp.compilers page.
Search the
comp.compilers archives again.