%left is not working

2010-08-03 Thread Sasan Forghani
Hello, I have been writing a simple compiler for a CS class and have run into a few problems that I can't figure out how to solve. %left does not seem to be working as Bison is derivating immediately. For example: a := b + c + d expr : expr ADDOP expr expr: ref_name ref_name: IDENTIFIER ADDOP

Re: %left is not working

2010-08-04 Thread Sasan Forghani
Aug 2010, at 23:13, Sasan Forghani wrote: > > Yes the lexer is generated by flex. In flex script, I have the actions: >> >> {addop} {yylval.blOperator = strdup(yytext); return BL_ADDOP;} >> {identifier} {yylval.blIdentifier = strdup(yytext); return BL_IDENTIFIER;} >>

Re: %left is not working

2010-08-04 Thread Sasan Forghani
14:17, Sasan Forghani wrote: > > I apologize for my lack of understanding. You said the next step is to >> clean it up in the actions... please clarify? >> > > When you allocate stuff using malloc, strdup, etc. when pointer is not used > anymore, to avoid memory le

Re: %left is not working

2010-08-04 Thread Sasan Forghani
ank you for the information. However, how does this relate to the >> $ problem I am having. To be more specific, the problem >> where >> the $ of the ASSIGNMENT production ends up with the same >> value >> of the ( expr ) production. >> >> On Wed, Aug 4,

Re: %left is not working

2010-08-05 Thread Sasan Forghani
So in any action for a production such as the expr production and specifically the expr : ( expr ) {some action}, specifying $$ will give expr its type. I.E expr : ( expr ) {$$; $$ = $2;} On Wed, Aug 4, 2010 at 5:30 PM, Hans Aberg wrote: > On 4 Aug 2010, at 21:48, Sasan Forghani wr

%left

2010-08-06 Thread Sasan Forghani
I've modified my code to the following: $$ = varLocation //at the ref_name rule level $$ = $2 //at the ( expr ) rule level $$ = bufferT //at the expr rule level The output is still incorrect. Moving up the stack the value does not hold. For example after derivating to the ref_name level for the

Re: %left

2010-08-09 Thread Sasan Forghani
uot;, $$); } stmt : ref_name BL_ASSIGNMENT expr { fprintf(ptrToIrFile, "mov %s %s\n", $3, $1); printf("$1 at := is: %s\n", $1); printf("$3 at := is: %s\n", $3); printf("$$ at := is: %s\n", $$); amtOfTe

update to %left is not working... still not working... trace of stack

2010-08-09 Thread Sasan Forghani
Below is some thinking I've done on the %left problem not working. I'm hoping that someone will see what is wrong and point it out to me so I can get the behavior I want. If input is a := b + c + d, Bison is adding c + d and then adding b. Since add is %left, it should add b + c and then d. Than

%left another thought

2010-08-09 Thread Sasan Forghani
In the ref_name production, I have the following statement: $$ = strdup(varLocation). varLocation is local buffer. In the ( expr ) production, I have the statement $$ = $2. Am I correct in thinking that I shouldn't have to use strdup() here since expr in ( expr ) will be getting its value from t

%left solved

2010-08-09 Thread Sasan Forghani
It seems that my code was somehow effecting how Bison was parsing. Or at least this is the assumption I am left making. After deleting all the code that had anything to do with the %left issue, the Bison parse is correct. Or at least it is according to the printf statements. Using the printf state

how to send data up the stack

2010-08-09 Thread Sasan Forghani
After the %left issue, the issue left is how to send data up the stack. Once a production such as expr : expr + expr is reduced and the actions performed how can I send data to the next reduction? ___ help-bison@gnu.org http://lists.gnu.org/mailman/listin

Re: how to send data up the stack

2010-08-10 Thread Sasan Forghani
therwise sent out your actual bison source file? Would that be possible to > do? It might not be, due to company IP concerns, etc, but at least those of > us trying to help you wouldn't be shooting in the dark so much. :) > > -Chris > > > > On Mon, Aug 9, 2010 at 2:27