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 02-22-2011, 11:34 PM   #1
savio84
LQ Newbie
 
Registered: Feb 2011
Posts: 2

Rep: Reputation: 0
Problem with bison 2.4.1


Hi,
Iam using fedora 11 version.

I have a problem with bison 2.4.1.
I am writing compiler for ADA programs

%token INTEGER_TOK 347

%left AND_TOK OR_TOK XOR_TOK
%left EQUAL_TOK NOT_EQUAL_TOK LESS_TOK GREATER_TOK LESS_EQUAL_TOK GREATER_EQUAL_TOK
%left PLUS_TOK MINUS_TOK
%left MULT_TOK DIVIDE_TOK MOD_TOK REM_TOK
%left DOUBLE_STAR_TOK ABS_TOK
%right NOT_TOK
%left UPLUS UMINUS
}%

unary_operator :
PLUS_TOK %prec UPLUS
{
if(trace) printf("Unary_operator 1\n");
$$.st_ptr=mknode1("adding_operator",NULL,mknode1("PLUS_TOK",NULL,NULL,NULL,NULL),NULL,NULL);
}
|MINUS_TOK %prec UMINUS
{
if(trace) printf("Unary_operator 2\n");
$$.st_ptr=mknode1("adding_operator",NULL,mknode1("MINUS_TOK",NULL,NULL,NULL,NULL),NULL,NULL);
}
;


Here %token is working.
But operator precedence relation is not working.

Operator precedence relation code is
%left AND_TOK OR_TOK XOR_TOK
%left EQUAL_TOK NOT_EQUAL_TOK LESS_TOK GREATER_TOK LESS_EQUAL_TOK GREATER_EQUAL_TOK
%left PLUS_TOK MINUS_TOK
%left MULT_TOK DIVIDE_TOK MOD_TOK REM_TOK
%left DOUBLE_STAR_TOK ABS_TOK
%right NOT_TOK
%left UPLUS UMINUS


is not working.

i believe this is a problem with bison.

For example

if give an operation

a:=2*3**2/9 mod 2+b*2 rem 2;

then first operation should be exponential operation
then multiplication. Instead it works in the order it is given.
 
Old 03-25-2011, 07:55 PM   #2
famsinyi
LQ Newbie
 
Registered: Nov 2007
Posts: 25

Rep: Reputation: 0
Quote:
Originally Posted by savio84 View Post
Hi,
Iam using fedora 11 version.

I have a problem with bison 2.4.1.
I am writing compiler for ADA programs

%token INTEGER_TOK 347

%left AND_TOK OR_TOK XOR_TOK
%left EQUAL_TOK NOT_EQUAL_TOK LESS_TOK GREATER_TOK LESS_EQUAL_TOK GREATER_EQUAL_TOK
%left PLUS_TOK MINUS_TOK
%left MULT_TOK DIVIDE_TOK MOD_TOK REM_TOK
%left DOUBLE_STAR_TOK ABS_TOK
%right NOT_TOK
%left UPLUS UMINUS
}%

unary_operator :
PLUS_TOK %prec UPLUS
{
if(trace) printf("Unary_operator 1\n");
$$.st_ptr=mknode1("adding_operator",NULL,mknode1("PLUS_TOK",NULL,NULL,NULL,NULL),NULL,NULL);
}
|MINUS_TOK %prec UMINUS
{
if(trace) printf("Unary_operator 2\n");
$$.st_ptr=mknode1("adding_operator",NULL,mknode1("MINUS_TOK",NULL,NULL,NULL,NULL),NULL,NULL);
}
;


Here %token is working.
But operator precedence relation is not working.

Operator precedence relation code is
%left AND_TOK OR_TOK XOR_TOK
%left EQUAL_TOK NOT_EQUAL_TOK LESS_TOK GREATER_TOK LESS_EQUAL_TOK GREATER_EQUAL_TOK
%left PLUS_TOK MINUS_TOK
%left MULT_TOK DIVIDE_TOK MOD_TOK REM_TOK
%left DOUBLE_STAR_TOK ABS_TOK
%right NOT_TOK
%left UPLUS UMINUS


is not working.

i believe this is a problem with bison.

For example

if give an operation

a:=2*3**2/9 mod 2+b*2 rem 2;

then first operation should be exponential operation
then multiplication. Instead it works in the order it is given.
How many sift-reduce conflicts bison reported? Have u look into the parse tree to see why?
 
  


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
Is there any support for bison-bridge and bison-locations in flex on windows systems? rami alkhateeb Linux - Software 0 12-29-2010 09:10 AM
Problem installing Bison 2.4.1 on Suse 11.1 Takuan Linux - Newbie 1 10-13-2009 10:59 AM
makefile problem with gcc bison/flex on ubuntu garvey Linux - Software 0 03-16-2009 04:31 PM
Bison and Yacc Compatibility Problem oulevon Programming 1 10-23-2005 10:56 PM
bison, flex and make problem ChimpFace9000 Programming 4 05-19-2002 07:49 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:25 AM.

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
Open Source Consulting | Domain Registration