Javalette.cf

31 views
Skip to first unread message

Maria Lemon Sjölander

unread,
Apr 17, 2011, 5:50:13 AM4/17/11
to Compiler construction 2011
I just have a question about the provided grammar. It has a reduce/
reduce conflict in it when I downloaded it from the homepage, I am
just wondering if we are supposed to fix this?

*** Reduce/Reduce conflict found in state #64
between Item ::= _IDENT_ (*)
and Expr6 ::= _IDENT_ (*)
under symbols: {_SYMB_5}
Resolved in favor of the first production.

Björn von Sydow

unread,
Apr 17, 2011, 1:32:54 PM4/17/11
to compiler-cons...@googlegroups.com
Hi, Maria!

Hmm, this is strange. There should definitely *not* be a reduce/reduce conflict in the grammar -- and I don't get one when I run cup on the file bnfc generates:

java -cp ../lib/java_cup-0.10.jar:../lib/java_cup-runtime-0.10.jar  java_cup.Main -expect 1 Javalette.cup
Opening files...
Parsing specification from standard input...
Checking specification...
Building parse tables...
  Computing non-terminal nullability...
  Computing first sets...
  Building state machine...
  Filling in tables...
*** Shift/Reduce conflict found in state #53
  between Stmt ::= _SYMB_27 _SYMB_0 Expr _SYMB_1 Stmt (*) 
  and     Stmt ::= _SYMB_27 _SYMB_0 Expr _SYMB_1 Stmt (*) _SYMB_25 Stmt 
  under symbol _SYMB_25
  Resolved in favor of shifting.


The shift/reduce conflict is expected (the dangling else conflict), but not a reduce/reduce conflict. Did you edit the BNFC file?

Best regards

Björn

Maria Lemon Sjölander

unread,
Apr 18, 2011, 4:28:50 AM4/18/11
to Compiler construction 2011
Only changes I did was add an Expr at top lvl

Expr = Type Expr

and change RelOp into two different ones.

ERel. Expr2 ::= Expr2 RelOp Expr3 ;

EEQNE. Expr2 ::= Expr2 RelOptwo Expr3 ;


LTH. RelOp ::= "<" ;

LE. RelOp ::= "<=" ;

GTH. RelOp ::= ">" ;

GE. RelOp ::= ">=" ;

EQU. RelOptwo ::= "==" ;

NE. RelOptwo ::= "!=" ;

and added the type String. Which shouldn't effect the reduce/reduce
conflict.

Strin. Type ::= "String" ;

Maria Lemon Sjölander

unread,
Apr 18, 2011, 4:41:11 AM4/18/11
to Compiler construction 2011
Checked the grammar and added one change at the time and it was the
Expr = Type Expr that made the reduce/reduce conflict. Now I just have
to find a way to sove it.

Peter

unread,
Apr 18, 2011, 6:19:57 PM4/18/11
to Compiler construction 2011
Just look through the BNFC documentation for the directive "internal",
it might be useful.

On Apr 18, 10:41 am, Maria Lemon Sjölander <maria.lemo...@gmail.com>
wrote:

Maria Lemon Sjölander

unread,
Apr 19, 2011, 5:15:07 AM4/19/11
to Compiler construction 2011
Thanks for the tip!
Reply all
Reply to author
Forward
0 new messages