#7 Targets with empty right-hand side problematic in Java mode

code (8)

Concerns version 1.14

If a target has an empty right-hand side, assigning to $$ in Java mode may lead to unpredictable results, because values may get unexpectedly overwritten.

The problem does not occur when C code is generated.

I attach one rules file for Java and one for C++, which both do essentially the same thing. There is also an input file valid for both.

Test case in C mode:

byacc mini.y
g++ -o mini y.tab.c
mini mini.in

Test case in Java mode:

byacc -Jclass=Mini minij.y
javac Mini.java
java Mini mini.in

The output should be the same, but isn't.

The reason is the statement

if (yym>0) //if count of rhs not 'nil'
yyval = val_peek(yym-1); //get current semantic value

just before the "switch(yyn)" statement in "Mini.java".

If a target has no right-hand side, yym is zero and yyval is not assigned for the rule. Is has whatever value it had from the previous rule. This "if" condition is not present in the generated C code.

I have made a temporary fix by removing the "if" in "skeleton.c" and making a little change in "output.c" to how the method "val_peek" is generated.

This seems to remedy the situation, but because I don't fully understand the code, I may have overlooked something and created a potential new problem.

Please find attached the two changed sources for reference.


  • MR212

    MR212 - 2007-01-08

    Tar ball with example files and modified sources

  • Adrian Jackson

    Adrian Jackson - 2008-09-19

    Has any progress been made on this bug? I've run into the same issue, and am also somewhat nervous about making the same change in case there's a valid reason for it working this way.

  • Tomas Hurka

    Tomas Hurka - 2008-09-19

    I am sorry, I forgot about this issue. I will look at it in the near future.

  • Tomas Hurka

    Tomas Hurka - 2008-11-15

    This problem has the same cause as issue #1638577. I tested the byacc/j with the fixed issue #1638577 and it also fixed this one. Closing as duplicate.

  • Tomas Hurka

    Tomas Hurka - 2008-11-15
    • status: open --> closed-duplicate

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks