LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 05-10-2005, 10:27 AM   #1
csikel
LQ Newbie
 
Registered: May 2005
Location: Thessaloniki,Greece
Distribution: Fedora Core 3
Posts: 4

Rep: Reputation: 0
Conflict resolution with bison


Suppose I have the following bison rules:

Rule1: FLOAT
: FLOAT FLOAT;
Rule2: FLOAT;
Rule3:Rule1 Rule2;

Obviously there is one shift\reduce conflict, because in sight of a second float the parser will have 2 options; reduce Rule1 and shift or shift the float. How can I resolve this conflict WITHOUT rewriting the rules ie by using associativity and precedence?

Thank you in advance for any help.

C.S.
 
Old 05-28-2005, 06:07 PM   #2
ToniT
Senior Member
 
Registered: Oct 2003
Location: Zurich, Switzerland
Distribution: Debian/unstable
Posts: 1,357

Rep: Reputation: 47
I don't see any operators what to assosiate with or which precedence to set.
 
Old 05-30-2005, 09:24 AM   #3
csikel
LQ Newbie
 
Registered: May 2005
Location: Thessaloniki,Greece
Distribution: Fedora Core 3
Posts: 4

Original Poster
Rep: Reputation: 0
May be I was not clear enough. The default action for bison in case of a shift reduce/conflict is to shift, which in my application is fine. However it would be nice if bison was told explicitly to shift when it encounters such shift/reduce conflicts. I was thinking something like, a float is associated with another float so in sight of a second float no ambiguity exists as far as what to do since the second float is associated with the first and therefore shifting is the appropriate action and not reducing. I hope I clarified things a little bit for what I woule like to achieve.

Thanks in advance for any help
C.S.
 
Old 06-01-2005, 07:46 AM   #4
ToniT
Senior Member
 
Registered: Oct 2003
Location: Zurich, Switzerland
Distribution: Debian/unstable
Posts: 1,357

Rep: Reputation: 47
ok. Pretending NUM to be an operator does the trick.

Code:
// Foo.y
%{
       #define YYSTYPE double
%}

%token NUM
%right NUM

%% 

        input: Rule1 Rule2 { $$ = $1 + 0.123 }
        ;


        Rule1: NUM NUM { $$ = $1 + $2; }
            | NUM { $$ = 0; }
        ;

        Rule2: NUM     { $$ = $1*10; }
        ;


%%
Swithing NUM to be a left associative causes reduce to be chosen instead of shift.

You can test that with
Code:
bison -r all foo.y
 
Old 06-06-2005, 04:53 AM   #5
csikel
LQ Newbie
 
Registered: May 2005
Location: Thessaloniki,Greece
Distribution: Fedora Core 3
Posts: 4

Original Poster
Rep: Reputation: 0
Thanx a lot. Unfortunately problem reports unsolved. Actually the rule layout is a little more complicated than I described. A more accurate description of the rules would be:
Rule_1: FLOAT
| FLOAT FLOAT;
Rule_2: FLOAT;
Rule_3: Rule_1;
| Rule_1 Rule_2;

In case of 2 FLOATS Rule_1 will be reduced and therefore Rule_3. In case of 3 FLOATS Rule_1 and Rule_2 will be reduced and therefore Rule_3; However there is a shift-reduce conflict since in sight of the second FLOAT Bison would have 2 options shift it and reduce Rule_1 or reduce Rule_1 and than reduce Rule_2. The default action is shifting which is what I want, however the question of how to suppress warnings by explicitly telling Bison to shift remains.
Thank you in advance for any of your help.
C.S.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Conflict resolution when parsing with bison csikel Solaris / OpenSolaris 1 05-10-2005 10:45 AM
Library Conflict Resolution toadatrix Linux - Software 1 04-07-2004 10:50 AM
Installing Bison lectraplayer Linux - Newbie 2 09-25-2003 08:43 PM
need to find bison bicjoe Linux - Newbie 3 07-11-2003 07:35 PM
yacc, Bison Config Linux - General 6 02-21-2002 03:18 PM


All times are GMT -5. The time now is 10:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration